try to implode string using php and redis -


this php file:-

    <?php     require "predis-0.8/autoload.php";     predis\autoloader::register();     try {         $redis = new predis\client();         }catch (exception $e) {     };     $redis->del("aaa");     for($i=1;$i<=10;$i++)     {     $randno=rand('1','5');     $ec = $redis->set("arr",$randno);     $str = $redis->get("arr").",";     echo ($str);     }     $comma = implode(",", $str);     echo ($comma); ?> 

i using redis php.
try implode strint.
not work.
return me error. warning: implode(): invalid arguments passed
idea why fetch warning.
in advance.

you looking function explode not implode.

implode takes array , concatenates elements given string in between.

explode takes string , splits array @ places find given string removing string.

$arr = array( 'foo', 'bar'); $imp = implode(',', $arr); # $imp == 'foo,bar' $exp = explode(',', $imp); # $exp == array('foo', 'bar') 

edit:

after further reading of code. guess try store array within redis. achieve (and more complex data structures) need convert data string. easiest way achieve serialize , unserialize.

$data; # contains data , either array or objects or int or ... $redis->set('foo', serialize($data)); $other_data = unserialize($redis->get('foo')); # $other_data == $data 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -