Jump to content

key with multiple values storing


Recommended Posts


$data = "foo:home,food,brand:tulasi";
list($user, $uid) = explode(":", $data);
echo "kk".$uid."</br>";

i want store two values home and food into foo 

how to store

guide me



Link to comment
Share on other sites

What do you think that explode is doing for you?  Did you echo out your user and uid values after the explode

Here is what I get:

$data = "foo:home,food,brand:tulasi";
list($user, $uid) = explode(":", $data);
echo "user is $user and uid is $uid";


Link to comment
Share on other sites

3 hours ago, durga said:

$data = "foo:home,food,brand:tulasi";

Why reinvent a perfectly good Wheel?  
Compound data structures are already rather well catered for by [things like] JSON: 

$jsonText = '{"foo":["home","food"],"brand":"tulasi"}';
$json = json_decode( $jsonText );

echo count( $json->foo ); 
// 2

echo $json->brand; 
// 'tulasi'

var_dump( $json ); 
//object(stdClass)#1 (2) 
//  ["foo"]=> array(2) 
//  { 
//    [0]=> string(4) "home" 
//    [1]=> string(4) "food" 
//  } 
//  ["brand"]=> string(6) "tulasi" 

The problem with your code is that the comma character (",") is being used to separate both the top-level items (foo and brand) and the individual values of foo!  
The explode() function cannot tell the difference between these two usages of the comma character. 

   Phill  W.


Edited by Phi11W
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.