array_column in php
$key = array_search(3, array_column($users, 'user_id'));
$userName = $users[$key]['first_name'];
array_column in php
$key = array_search(3, array_column($users, 'user_id'));
$userName = $users[$key]['first_name'];
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
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us