Jump to content

Recommended Posts

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";
exit();

 

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. 

Regards, 
   Phill  W.

 

Edited by Phi11W
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

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

Guest
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.