and I want to remove the key "holiday_date" and get a falt arry
array('2010-01-01','2010-01-02',...)
is that a smarter way to do this rather then a loop?
Asked
Active
Viewed 362 times
0

johnn
- 317
- 1
- 5
- 15
-
Not clear enough. Please add some example of what you want and what have you tried to achieve this. – Sougata Bose Jul 02 '15 at 07:01
-
Could you show any code you're having. We're not here to just make the code you want, you have to try yourself, and if you're having problems, then ask for help here :) – Jesper Jul 02 '15 at 07:03
-
possible duplicate of [How to pull specific key values from array inside array](http://stackoverflow.com/questions/30863160/how-to-pull-specific-key-values-from-array-inside-array) – viral Jul 02 '15 at 09:03
1 Answers
1
You need to use array_column()
,
$tmp = array_column($tmp, 'holiday_date');
This will pull out 'holiday_date' values from your internal arrays, and we are storing them in $tmp
itself, so after this line, $tmp
will formed as you need.
Another Example: consider the below array,
$records = array(
array(
'id' => 2135,
'first_name' => 'John',
'last_name' => 'Doe',
),
array(
'id' => 3245,
'first_name' => 'Sally',
'last_name' => 'Smith',
));
Applying, array_column()
as below,
array_column($records, 'first_name');
will return,
Array
(
[0] => John
[1] => Sally
)
If using PHP version < 5.5, refer this quick implementation of array_column()
.
-
this is exactly what i want to do, unfortunately my php is 5.3 and do not have this function.>If using PHP version < 5.5, refer this, thank you I have resolved this problem. – johnn Jul 02 '15 at 07:17