I have a array print like this:
array(2) {
["systems"]=>
array(5) {
[1]=>
string(1) "1111"
[2]=>
string(1) "2222"
[3]=>
string(1) "3333"
[4]=>
string(1) "4444"
[5]=>
string(1) "5555"
}
["test"]=>
string(2) "on"
}
Now , i want to access to every every inner value with using foreach or any code that will work with that code.
I mean for example, I want to echo Out something like this :
System "1" has "1111" value.
System "2" has "2222" value.
System "3" has "3333" value.
System "4" has "4444" value.
System "5" has "5555" value.
How can i have that output code ?
Try this:
$array = array(
'systems' => array(
1 => 1111,
2 => 2222,
3 => 3333,
4 => 4444,
5 => 5555
),
'test' => 'on'
);
foreach ($array['systems'] as $key => $value) {
echo 'System "' . $key . '" has "' . $value . '" value.'."<br />
";
}
if your name of your variable is $array
.
Such as the following.
foreach ($array as $key => $subarray){
foreach ($subarray as $name => $value){
echo '<p>'.$key.' "'.$name.'" has "'.$value.'" value.</p>';
}
}
foreach ($array['systems'] as $key1 => $value1) {
echo "SYSTEM".$key1."has".$value1."value";
echo "<br>";
}