Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php array associatif move element

function moveKeyBefore($arr, $find, $move) {
    if (!isset($arr[$find], $arr[$move])) {
        return $arr;
    }

    $elem = [$move=>$arr[$move]];  // cache the element to be moved
    $start = array_splice($arr, 0, array_search($find, array_keys($arr)));
    unset($start[$move]);  // only important if $move is in $start
    return $start + $elem + $arr;
}
$arr = ['foo1'=>'bar', 'foo2'=>'buzz', 'foo3'=>'bazz'];
var_export(moveKeyBefore($arr, 'foo3', 'foo1'));
Comment

PREVIOUS NEXT
Code Example
Php :: fpdf tutorial php mysql 
Php :: how to change php to html 
Php :: laravel 8 remove public folder from url 
Php :: php replace all text from string with associate array values 
Php :: how to sum values of two product which are same gst rate and this product are come from foreach loop in php 
Php :: pass variable in laravel ancher tag laravel 8 
Php :: tina4 save file to database in orm 
Php :: php preg_match html cross origin 
Php :: inject multiple logger symfony 
Php :: How to automail in php 
Php :: how to change phpto size in its properties ubuntu 
Php :: PHP number_format — Format a number with grouped thousands 
Php :: livewire mount return type 
Php :: how to create php message 00 
Php :: laravel collection makeVisible 
Php :: example of valid php variables 
Php :: php how to use namespaces 
Php :: singular from table laravel 
Php :: Who is known as the father of PHP? 
Php :: php check if cli mode 
Php :: WooCommerce quantity field to ajax add to cart button archive page 
Php :: Including ACF in a custom theme or plugin 
Php :: javascript date to php date site:stackoverflow.com 
Php :: replace class 
Php :: Laravel 9.x Target class does not exist error at login application 
Php :: implode (PHP 4, PHP 5, PHP 7, PHP 8) implode — Join array elements with a string 
Php :: popup en php 
Php :: laravel factory counter 
Php :: laravel blade all syntex description 
Php :: ?id=$1&user=$2 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =