开发者

parsing a php value

for example:

$value_array = array("fu" => "bar", "banana" => "apple");

for example:

echo $value_array["fu"]; # output will be bar

okay, i have this va开发者_如何学编程lue:

$value = "fuu:bar:12:apple";

okay, i'd like to parse the $value and write "bar" value to the screen, but i don't know how i can do this job.


umm, why delimit by :? It'd be a lot easier with fuu:bar;12:apple but to go with what you have...

$value = explode(':',$value);
$values = array();
foreach ($value as $k => $v) {
   if ($k %2 != 0)
      $values[$value[($k - 1)]] = $v;
}


Try using explode function.


$bar_val  = explode(":", $value);

echo $bar_val[1];

Demo: http://codepad.org/pyoyfk8n

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜