John Smith
John Smith

Reputation: 1099

print array values separately

I have created an array in php that prints this

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

How i can print the marks separately from the array. e.g just print out 3.

Upvotes: 3

Views: 9418

Answers (3)

Dogbert
Dogbert

Reputation: 222108

Assuming $array is your array:

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

Upvotes: 6

PeeHaa
PeeHaa

Reputation: 72652

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

You can print a specific element by using for example:

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

You could also loop through the array:

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

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

Upvotes: 1

safrazik
safrazik

Reputation: 1601

to print all values:

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

Upvotes: 1

Related Questions