Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php collapse common columns in associative array

/* Collapse on common columns which is also the new key e.g.
([0] => [[id] => 1234, [firstName] => "foo", [1] => [[id] => 1234, [lastName] => "bar")
will become ([1234] => [[firstName] => "foo", [lastName]="bar"]
Credit to https://stackoverflow.com/users/762073/xdazz
*/
$result = array();
foreach ($data as $element) {
    $result[$element['id']][] = $element;// [] appends to the array if it already exists
}
Comment

PREVIOUS NEXT
Code Example
Php :: css en linea php 
Php :: session flash data (old input) 
Php :: Drupal config_readonly 
Php :: Same Taxonomy Add Multiple Post Type 
Php :: Get authors who has posts in category - WordPress 
Php :: prevent cross site scripting php 
Php :: laravel Undefined index: token on reset 
Php :: pcntl_fork php mysql "MySQL server has gone away" 
Php :: convert code python to php 
Php :: installing php storm version 20 in ubuntu 
Php :: 0 == "string" php 
Php :: Random select value on array factory Laravel 
Php :: find only selected columns 
Php :: url images in CSS file link not working on PHP page| 
Php :: wordpress pass parameters variables arguments to enqueued script 
Php :: wordpress profile queries 
Php :: dir_instalación_Zend_Studiopluginscom.zend.php.debug.debugger.win32.x86_10.6.0.v20140121-1240 esourcesphp.ini 
Php :: small rce php 
Php :: I wanna add new tab clientarea in whmcs 
Php :: laravel store mail driver info in database 
Php :: Régler l’enregistrement automatique dans WordPress 
Php :: folder name escape php 
Php :: dont allow this command to every one set in meddlware laravel 
Php :: Best Performance monitoring tools for php 
Php :: yii1 anchor tag 
Php :: add code return block phpstorm 
Php :: Autoriser les contributeurs à télécharger des images 
Php :: php validate email 
Php :: php 7.1.1 download 
Php :: upgrade php 5.6 to 7 centos 7 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =