This question already has answers here:
How can I access an array/object?
(6 answers)
Closed 1 year ago.
Array
(
[result] => 0
[room] => Array
(
[name] => room for one to one video meeting: 306100
[service_id] => 5f6c5b420dd7940701cc36b1
[owner_ref] => 306100
[settings] => Array
(
[mode] => group
[scheduled] =>
[adhoc] => 1
[duration] => 30
[participants] => 1
[auto_recording] =>
[screen_share] => 1
[canvas] =>
[media_configuration] => default
[quality] => SD
[moderators] => 1
[active_talker] => 1
[max_active_talkers] => 1
[single_file_recording] =>
[media_zone] => XX
)
[sip] => Array
(
[enabled] =>
)
[created] => 2021-04-19T05:52:26.779Z
[room_id] => 607d1a9a4e11874ceda79a96
)
)
how to find room_id this array
The array_search() function searches an array for a given value and returns the key. The function returns the key for val if it is found in the array. It returns FALSE if it is not found. If val is found in the array arr more than once, then the first matching key is returned.
Syntax
array_search(val, arr, strict)
Parameters
val − The value to be searched
arr − The array to be searched
strict − Possible values are TRUE or FALSE. Search for identical elements in the array, set to TRUE.
example :-
<?php
$arr = array("p"=>20,"q"=>20,"r"=>30,"s"=>40);
echo array_search(20,$arr,true);
?>
Related
This question already has answers here:
How to get single value from this multi-dimensional PHP array [duplicate]
(6 answers)
Closed 5 years ago.
I have an array:
print_r($response);
will show:
Response: Array
(
[errors] => false
[return] => Array
(
[price_recurring] => 0
[country_code] => NL
[invoicemethod] => instant
[product_id] => 0
[affiliate] =>
[number_of_periods] => 1
[description] => Betaling voor eventid 274
[period_duration] => 1 month
[date] => 29/11/2017 19:42
[order_quantity] => 1
[vat] => 21
[amount_total] => 4599
[total_paused_days] => 0
[custom] => WEB1511980957x194237
[emailaddress] => ik#ik.nl
[amount_affiliate_initial] => 0
[total] => 45,99
[current_status] => completed
[amount_affiliate_recurring] => 0
[amount_total_affiliate] => 0
[id] => 1790226
[price_initial] => 4599
[current_number_of_periods] => 1
[firstname] =>
)
)
How can i extract the value 'custom'?
I've tried:
$response = array_shift($response);
echo $response['custom'];
but it will show nothing. What am i doing wrong here? I know i am close.
$response is an array with two keys errors and return. $response['return'] in turn, is an array with several keys, including custom. Therefore, to access custom, you need to reference $response['return']['custom']
you have an array inside an array
$response["return"]["custom"]
also try to var_dump (or print_r depends on what you prefer) instead of echoing when you try to navigate
var_dump( $response["custom"]);
would tell you a lot more than echoing null, which prints nothing
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.
This question already has answers here:
How do I Sort a Multidimensional Array in PHP [duplicate]
(10 answers)
Closed 7 years ago.
I want to sort this array on basis of 'eta'.Lowest eta must come to first.
My array is :
Array
(
[0] => Array
(
[company] => Uber
[type] => Saloon
[eta] => 8
[destination_required] => N
[reject_booking_request] => N
)
[1] => Array
(
[company] => greentomato
[type] => Saloon
[company_rating] => 80%
[eta] => 10
[destination_required] => N
[reject_booking_request] => N
)
[2] => Array
(
[company] => CATALINA
[type] => Exec
[eta] => 12
[destination_required] => Y
[reject_booking_request] => N
)
[3] => Array
(
[company] => Uber
[type] => Exec
[eta] => 15
[destination_required] => N
[reject_booking_request] => N
)
[4] => Array
(
[company] => Hailo
[type] => Taxi
[eta] => 1
[destination_required] => Y
[reject_booking_request] => Y
)
)
I want to sort this array on basis of 'eta'.Lowest eta must come to first.
I tried to use this :
$result = Set::sort($array, '{n}', 'asc');
But it gives some error.
You can use usort:
usort($yourArray, function($a, $b) {
return $a['eta'] - $b['eta'];
});
Usort allows the definition of a custom sortation callback function as the second parameter. Inside the body of this method you can define your comparison algorithm.
If the method returns a negative number it will move the $b variable down the array, returning a positive number will move $b up the array and return 0 keeps $b in the same place.
We have defined an inline callback method for simplicity sake.
I did that in cakephp :
My Ans is :
Hash::sort($array, '{n}.eta', 'asc');
You can use array multisort function.
Follow the link for more information.
http://php.net/manual/en/function.array-multisort.php
I am not really familiar on how php handles array, in .NET I can access array using this method
array[x][y];
My question is:
I am retrieving records from the database and returning it to the $res_merchant_field
$res_merchant_field = $this->CI->merchantfield_model->merchantfield_list( $str_where );
and $res_merchant_field will be populated with this record:
Array
(
[0] => stdClass Object
(
[MFID] => 1
[MFName] => Bill No
[FTID] => 1
[DTID] => 1
[MFRequired] => 1
[MFDefaultValue] =>
[MFDueDate] => 0
[MFToBePaid] => 0
[MFMaxLength] => 12
[MFOrderNo] => 1
[MFStatus] => 1
)
[1] => stdClass Object
(
[MFID] => 2
[MFName] => Gallons Consumed
[FTID] => 1
[DTID] => 2
[MFRequired] => 1
[MFDefaultValue] =>
[MFDueDate] => 0
[MFToBePaid] => 0
[MFMaxLength] => 5
[MFOrderNo] => 2
[MFStatus] => 1
)
[2] => stdClass Object
(
[MFID] => 3
[MFName] => Amount Due
[FTID] => 3
[DTID] => 1
[MFRequired] => 1
[MFDefaultValue] =>
[MFDueDate] => 0
[MFToBePaid] => 1
[MFMaxLength] => 15
[MFOrderNo] => 3
[MFStatus] => 1
)
)
How can I access and fetch the record from that array with this condition:
it will look through all the array find specific index, lets say index 0 which is MFID,
after getting the MFID and comparing it with another variable, if it is true,
it will get the DTID for that array MFID.
example:
get MFID = 1, the DTID will be 1, if I get the MFID = 3, the DTID will be 1.
or how can I access the array like $array[x][y]?
Thanks in advance.
The problem is that the second level is not an array but instead an object, to access a property you will have to use this format.
$array[$x]->$y;
Unfortunately you cannot access a property by an index do o get the MFID of the 0th Item you will need to say
$array[0]->MFID;
This question already has answers here:
Sorting multidim array: prioritize if column contains substring, then order by a second column
(4 answers)
Sort multidimensional array by multiple columns
(8 answers)
Closed 9 years ago.
I have this Array
Array (
[0] => Array
(
[id] => 61
[testo] => articolo di maggio
[data] => 2013-05-03
[orario] => 00:00:00
[nome_files] => fabmad_1920x1200.jpg
[pubblicato] => 1
)
[1] => Array
(
[id] => 58
[testo] =>
[data] => 2013-06-03
[orario] => 00:00:00
[nome_files] => 20130603100647_da_installare.rtf
[pubblicato] => 1
)
[2] => Array
(
[id] => 59
[testo] => Demo
[data] => 2013-06-03
[orario] => 00:00:00
[nome_files] => eye_drops_water_2.jpg
[pubblicato] => 1
)
)
I want to sort it by "data".
I want to display the "data" and for each data the elements...
Try the ksort function or the array-multisort
Check the php documentation: http://php.net/manual/en/function.ksort.php
http://php.net/manual/en/function.array-multisort.php