Print array values ​​separately

I created an array in php that prints this

Array ( [mark] => Array ( [0] => 3 [1] => 4 ) )

      

How can I print the marks separately from the array. for example just print 3.

+3


source to share


3 answers


Assuming $array

- your array:



echo $array['mark'][0];

      

+6


source


to print all values:



foreach($array as $value){
 echo $value."<br />";
}

      

+1


source


$myArray = array('mark'=>array(3, 4));

      

You can print a specific element using for example:

echo $myArray['mark'][0]; // this would print out 3

      

You can also loop through the array:

foreach($myArray['mark'] => $item) {
    echo $item;
}

// this would result it the printing of 3 first and then 4

      

+1


source







All Articles