<?php
$records = array(
array(
'id' => 2135,
'first_name' => 'John',
'last_name' => 'Doe',
),
array(
'id' => 3245,
'first_name' => 'Sally',
'last_name' => 'Smith',
),
array(
'id' => 5342,
'first_name' => 'Jane',
'last_name' => 'Jones',
),
array(
'id' => 5623,
'first_name' => 'Peter',
'last_name' => 'Doe',
)
);
foreach($records as $key=> $value){
foreach($records[$key] as $value ){
echo " $value <br>";
}
}
?>
2135
John
Doe
3245
Sally
Smith
5342
Jane
Jones
5623
Peter
Doe
More advanced method
<?php
$records = array(
array(
'id' => 2135,
'first_name' => 'John',
'last_name' => 'Doe',
),
array(
'id' => 3245,
'first_name' => 'Sally',
'last_name' => 'Smith',
),
array(
'id' => 5342,
'first_name' => 'Jane',
'last_name' => 'Jones',
),
array(
'id' => 5623,
'first_name' => 'Peter',
'last_name' => 'Doe',
)
);
foreach($records as $key=> $value){
echo " Array # $key<br>";
foreach($records[$key] as $value){
echo " $value<br>";
}
}
?>
Array # 0
2135
John
Doe
Array # 1
3245
Sally
Smith
Array # 2
5342
Jane
Jones
Array # 3
5623
Peter
Doe
Other conditional method
<?php
$records = array(
array(
'id' => 2135,
'first_name' => 'John',
'last_name' => 'Doe',
),
array(
'id' => 3245,
'first_name' => 'Sally',
'last_name' => 'Smith',
),
array(
'id' => 5342,
'first_name' => 'Jane',
'last_name' => 'Jones',
),
array(
'id' => 5623,
'first_name' => 'Peter',
'last_name' => 'Doe',
)
);
foreach($records as $key=> $value){
if($key==3){
foreach($records[$key] as $value){
echo " $value<br>";
}
}
}
?>
5623
Peter
Doe
Displaying only ID key
<?php
$records = array(
array(
'id' => 2135,
'first_name' => 'John',
'last_name' => 'Doe',
),
array(
'id' => 3245,
'first_name' => 'Sally',
'last_name' => 'Smith',
),
array(
'id' => 5342,
'first_name' => 'Jane',
'last_name' => 'Jones',
),
array(
'id' => 5623,
'first_name' => 'Peter',
'last_name' => 'Doe',
)
);
foreach($records as $key=> $value){
foreach($records[$key] as $key=> $value){
if($key=="id"){
echo " $value<br>";
}
}
}
?>
2135
3245
5342
5623
No hay comentarios:
Publicar un comentario