note 109718 added to function.array-replace
| From: | steelpandrummer | Date: | Tue, 14 Aug 2012 09:19:19 +0000 |
| Subject: | note 109718 added to function.array-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-190060@lists.php.net to get a copy of this message | ||
<?php
// we wanted the output of only selected array_keys from a big array from a csv-table
// with different order of keys, with optional suppressing of empty or unused values
$values = array
(
'Article'=>'24497',
'Type'=>'LED',
'Socket'=>'E27',
'Dimmable'=>'',
'Wattage'=>'10W'
);
$keys =
array_fill_keys(array('Article','Wattage','Dimmable','Type','Foobar'),
''); // wanted array with empty value
$allkeys = array_replace($keys, array_intersect_key($values, $keys)); // replace only the wanted
keys
$notempty = array_filter($allkeys, 'strlen'); // strlen used as the callback-function with
0==false
print '<pre>';
print_r($allkeys);
print_r($notempty);
/*
Array
(
[Article] => 24497
[Wattage] => 10W
[Dimmable] =>
[Type] => LED
[Foobar] =>
)
Array
(
[Article] => 24497
[Wattage] => 10W
[Type] => LED
)
*/
?>
----
Server IP: 212.124.37.9
Probable Submitter: 195.243.218.154
----
Manual Page -- http://www.php.net/manual/en/function.array-replace.php
Edit -- https://master.php.net/note/edit/109718
Del: integrated -- https://master.php.net/note/delete/109718/integrated
Del: useless -- https://master.php.net/note/delete/109718/useless
Del: bad code -- https://master.php.net/note/delete/109718/bad+code
Del: spam -- https://master.php.net/note/delete/109718/spam
Del: non-english -- https://master.php.net/note/delete/109718/non-english
Del: in docs -- https://master.php.net/note/delete/109718/in+docs
Del: other reasons-- https://master.php.net/note/delete/109718
Reject -- https://master.php.net/note/reject/109718
Search -- https://master.php.net/manage/user-notes.php