I'm trying to get the value of the array, but I just cant quite get to it. I'm trying with a foreach loop and with key and values. But I can't get it right. I'm working with wordpress custom field, and I'm trying to retrieve product ID, so that I can manipulate website data.
This is the array:
'Izbrani izdelki'
array (
0 =>
array (
'product' => 34,
),
1 =>
array (
'product' => 35,
),
2 =>
array (
'product' => 41,
),
3 =>
array (
'product' => 51,
),
4 =>
array (
'product' => 40,
),
)
'Novo v naši ponudbi'
array (
0 =>
array (
'product' => 35,
),
1 =>
array (
'product' => 35,
),
2 =>
array (
'product' => 32,
),
3 =>
array (
'product' => 51,
),
4 =>
array (
'product' => 37,
),
)
'Najbolj prodajani izdelki'
array (
0 =>
array (
'product' => 34,
),
1 =>
array (
'product' => 41,
),
2 =>
array (
'product' => 35,
),
3 =>
array (
'product' => 51,
),
4 =>
array (
'product' => 39,
),
)
'Odprodaja'
array (
0 =>
array (
'product' => 36,
),
1 =>
array (
'product' => 34,
),
2 =>
array (
'product' => 41,
),
3 =>
array (
'product' => 51,
),
4 =>
array (
'product' => 41,
),
)
And I'm trying to retrieve value "product", to be more specific the value number that's inside with this approach:
<?php foreach ($tabTitle as $key => $value): ?>
<?php foreach ($value as $key2 => $value2): ?>
<?php
echo "<pre>";
var_dump( $value2);
echo "</pre>";
?>
<?php endforeach; ?>
<?php endforeach; ?>
My Answer:
> To access the value of the array inside two arrays, you can use nested foreach loops. Here's an example code snippet to help you retrieve the product ID:
php
// Assuming $izbrani_izdelki is the array you provided
foreach ($izbrani_izdelki as $izdelki) {
foreach ($izdelki as $product_id) {
echo $product_id;
}
}
In this code snippet, we are iterating over the outer array `$izbrani_izdelki` and then iterating over the inner array `$izdelki` to access the product ID value. You can replace `echo $product_id;` with your desired manipulation logic.
Rate this post
3 of 5 based on 1512 votesComments