php - Assocative array loop only prints first 2 characters -


i trying access value associative array, loop printing first 2 characters first element.

<?php   $memserver = array(          array("ipsssss" , "port")  //i want print first element     );   for($i = 0; $i< count($memserver); $i++) { for($j = 0; $j<count($memserver[$i]); $j++) {      echo $memserver[$i][$j][0]; } } ?> 

first of all, not associative array. example of associative array array('key' => 'value').

the loop not printing the first 2 characters of first element; printing first character (i) of "ipsssss" , first character (p) of "port".

you must rid of inner loop:

for($i = 0; $i< count($memserver); $i++) {     //for($j = 0; $j<count($memserver[$i]); $j++)     //{     echo $memserver[$i][0];     //} } 

(or use foreach construction described john conde).


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -