I have the following array $foo
array(10) {
[0] => array(4) {
["merchantId"] => string(5) "12e21"
["programId"] => string(27) "ddd3333"
["networkId"] => int(4)
["clientId"] => int(178)
}
[1] => array(4) {
["merchantId"] => string(5) "112e1"
["programId"] => string(27) "2vfrdbv1&=10&tmfdpid=csss"
["networkId"] => int(4)
["clientId"] => int(178)
}
[2] => array(4) {
["merchantId"] => string(5) "112e1"
["programId"] => string(27) "2vfrdbv1&=10&tmfdpid=csss"
["networkId"] => int(4)
["clientId"] => int(178)
}
And I need an array of clientId's (only)
Is it possible to access just the clientId to create an array of id's without a loop?
Something like:
$foo['clientId']; //which doesn't work
Use filter if you want to find all items in an array that meet a specific condition. Use find if you want to check if that at least one item meets a specific condition. Use includes if you want to check if an array contains a particular value. Use indexOf if you want to find the index of a particular item in an array.
There are two types of arrays as 1D and 2D arrays. The main difference between 1D and 2D array is that the 1D array represents multiple data items as a list while 2D array represents multiple data items as a table consisting of rows and columns.
A multidimensional array is an array containing one or more arrays.
In the simplest terms, a one-dimensional array in C is a list. Each element of the list contains only one value, whether that value be an int, char, or float. To declare an array, three values are typically needed: the data type, name of the array, and the number of elements to be contained in the array.
In PHP 5.5:
$rgResult = array_column($foo, 'clientId');
in PHP <=5.5:
$rgResult = array_map(function($rgItem)
{
return $rgItem['clientId'];
}, $foo);
(put <=
since this, of cause, will work in 5.5 too)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With