Getting value from a multidimensional array [duplicate] - php

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'];

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'));

Comma separated value from array [duplicate]

This question already has answers here:
How to Flatten a Multidimensional Array?
(31 answers)
PHP - Multidimensional array to CSV
(3 answers)
How to write a multidimensional array to a csv file. PHP
(2 answers)
multidimensional irregular array to CSV in PHP
(1 answer)
Closed 3 years ago.
I need to explode stdentid array in comma separated value.currently the studentid array is in multidimensional array i need all the value should be in comma separated
The result should be for studentid array is
[studentid] => 36399,96500,96503,96509,96512 and so on..
Array
(
[started] => 1
[studentid] => Array
(
[1] => Array
(
[0] => 36399
)
[2] => Array
(
[0] => 96500
[1] => 96503
[2] => 96506
[3] => 96509
[4] => 96512
[5] => 96515
)
[3] => Array
(
[0] => 96501
[1] => 96504
[2] => 96507
[3] => 96510
[4] => 96513
)
[4] => Array
(
[0] => 96502
[1] => 96505
[2] => 96508
[3] => 96511
[4] => 96514
)
)
[name] => Test
[name_or_email] =>
[submitbtn] => 1
)
assuming your variable is $studentsResult (which contains the whole array you have posted)
in that case:
foreach($studentsResult['studentid'] as $studentId => $studentValues){
$tempStudents[$studentId] = join(',',$studentValues);
}
and then $tempStudents is what you're probably looking for\
If, however all those IDs needs to be under that ONE student, then you haven't said where is the ID, but you can follow the answer on flattening the array in one of the comments or do:
$tempStudents = [];
foreach($studentsResult['studentid'] as $someId => $studentValues){
$tempStudents = array_merge($tempStudents,$studentValues);
}
echo join(',',$tempStudents);

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

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
)
)
)
)

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