php - Why multidimensional array keeps return the key "0"? -


i have array this

$test = array("sumber"=>array("f1","f2"),"ukraina"=>array("f3","f4"),"0"=>array("f5","f6"));  foreach($test $key => $value){     if($key=="sumber"){     $a='';     for($i=0;$i<count($value);$i++){         $a.=$value[$i].", ";     }     echo $key." has ".$a."<br/>";     } } 

and want result only

sumber has f1, f2,

but result this

sumber has f1, f2,

0 has f5, f6,

please me how display key "sumber" only??? thanks.

use triple conditional === in if($key=="sumber") condition:

$test = array("sumber"=>array("f1","f2"),"ukraina"=>array("f3","f4"),"0"=>array("f5","f6"));  foreach($test $key => $value){     if($key==="sumber"){     $a='';     for($i=0;$i<count($value);$i++){         $a.=$value[$i].", ";     }     echo $key." has ".$a."<br/>";     } } 

otherwise if() condition accomplished when key empty/0.


Comments

Popular posts from this blog

iphone - Three second countdown in cocos2d -

hyperlink - how to do url routing in php -

c - Avoiding Extra Malloc in Linked List (node->next = NULL) -