Array, which is in Object, which is in Array [duplicate] - php

This question already has answers here:
How can I access an array/object?
(6 answers)
How do I retrieve an item from an PHP Object Array?
(2 answers)
Closed 5 years ago.
I want to take this value
_wc_deposits_original_total [value] => 828.00
Excatly I mean number "828.00"
I've been trying like this "array[][]" but there's object inside the array and I dont know how to display it.
Array(
[meta_data] => Array (
[1] => WC_Meta_Data Object (
[current_data:protected] => Array (
[id] => 12025
[key] => _wc_deposits_original_total
[value] => 828.00
)
[data:protected] => Array (
[id] => 12025
[key] => _wc_deposits_original_total
[value] => 828.00
)
)
)
)

Related

How can I get multiple values from array within array? [duplicate]

This question already has answers here:
How to extract specific array keys and values to another array?
(2 answers)
Closed 2 years ago.
I have an array that looks like this:
[meta_data] => Array
[0] => Array
(
[id] => 100
[name] => John
)
[1] => Array
(
[id] => 200
[name] => Peter
)
[2] => Array
(
[id] => 300
[name] => Peter
)
What would be the simplest way to select all names from $meta_data?
Thanks.
see https://www.php.net/manual/en/function.array-column.php
var_dump(array_column($array['meta_data'], 'name'));

Getting value from a multidimensional array [duplicate]

This question already has answers here:
How can I access an array/object?
(6 answers)
Closed 5 years ago.
I have an array $rates
I used print_r to see if I have the values I want. And returns the information below.
Array (
[125] => Array (
[2011] => Array (
[ca] => Array (
[8810] => Array (
[0] => Array (
[Key] => 481
[Code] => 8810
[Desc] => Clerical Office Employees - NOC
[Desc_escaped] => Clerical Office Employees - NOC
[Rate] => 0.82
[Exclusion] => 0
[peo_id] =>
)
)
)
)
)
)
I have tried a number of methods to get the info I want but have been unsuccessful. I am after the value of [Rate]
Try
$rates[125][2011]['ca'][8810][0]['Rate'];

How can I access array's item when there is an object in it? [duplicate]

This question already has answers here:
How can I access an array/object?
(6 answers)
Closed 5 years ago.
I have an array like this:
echo "<pre>";
print_r($res_users);
/*
Array
(
[0] => stdClass Object
(
[position] => 1
[user] => stdClass Object
(
[full_name] => دکوراسیون
[is_private] => 1
[has_anonymous_profile_picture] =>
[byline] => 39.3k followers
[profile_pic_url] => https://scontent-frt3-1.cdninstagram.com/t51.2885-19/s150x150/11352072_817936521647202_201395223_a.jpg
[pk] => 1480272396
[follower_count] => 39326
[is_verified] =>
[mutual_followers_count] => 0
[username] => sajad.sobhi
)
)
)
All I'm trying to do is selecting following URL from array above:
https://scontent-frt3-1.cdninstagram.com/t51.2885-19/s150x150/11352072_817936521647202_201395223_a.jpg
Which is the value of profile_pic_url. How can I get that?
Noted that this doesn't work:
echo $res_users[0]['user']['profile_pic_url'];
Try $res_users[0]->user->profile_pic_url. Because $res_users[0] is object type
Try it by this way
echo $res_users[0]->user->profile_pic_url;

Access to a specific array in php [duplicate]

This question already has answers here:
How can I access an array/object?
(6 answers)
Closed 6 years ago.
i create an array and i would like to access to the value but i really don't know how :
Here is my array :
Array
(
[0] => Array
(
[id] => 1
[id_orga] => 36094152
[nom] => Adresse externe
[url] => https://cubber.zendesk.com/api/v2/organizations/36094152.json
[created] => 2015-01-22 08:00:53
[updated] => 2015-01-22 08:00:53
[tickets] => Array
(
)
[monthly] => Array
(
[0] => ArrayObject Object
(
[storage:ArrayObject:private] => Array
(
[assist] => 0
[maint] => 0
[total] => 0
)
)
and i would like for example to access to the value "0" in the key "assist" and change it to "1" for example and i don't know how to do it.
Suppose the source array is called $myArray. Try:
$myArray[0]['monthly'][0]->storage['assist'] = 1
If that doesn't work, try:
$myArray[0]['monthly'][0]['storage']['assist'] = 1
Let me know which works so I delete the other.

How can I convert this array to an object? [duplicate]

This question already has answers here:
How to convert an array to object in PHP?
(35 answers)
Closed 8 years ago.
How can i convert an array like this to object?
Array
(
[max] => Array
(
[0] => 21.
[1] => male.
[2] => UK.
)
[alex] => Array
(
[0] => 20.
[1] => male.
[2] => sweden.
)
[ali] => Array
(
[0] => 20.
[1] => male.
[2] => saudi arabia.
)
)
i've alrady tried for each loop and it didn't work.
is there any way to convert it ?
Try this.
$object = json_decode(json_encode($array));
or you can also do this.
$object = (object) $array;
Here's a demo.

Categories