A PHP question about arrays

    array("name","1","xixi","php"); 

    array("name"=>"1","xixi"=>"php");

how is the above array processed into the following format?

Php
May.14,2021

<?php
$array = array('name','1','xixi','php');
//
$newArr = array_combine(
    //
    array_filter($array,
        function($key)
        {
            return !($key & 1);
        },ARRAY_FILTER_USE_KEY)
    ,
    //
    array_filter($array,
        function($key)
        {
            return $key & 1;
        },ARRAY_FILTER_USE_KEY)
);
print_r($newArr);

1:

$arrayA =  array('name','1','xixi','php'); 

function convertArrays($arrayA)
{
    $keys = array(); 
    $values = array(); 
    for($i = 0; $i < count($arrayA); $iPP)
    {
        if($i % 2 == 0) 
        {
            array_push($keys, $arrayA[$i]);
        }
        else 
        {
            array_push($values, $arrayA[$i]); 
        }
    }

    $arrayB = array();

    for($j = 0; $j < count($keys); $jPP)
    {
        $arrayB[ $keys[$j] ] = $values[$j];
    }

    return $arrayB;
}

2:

for($i=0; $i < count($arrayA); $i+=2){
    $arrayB[$arrayA[$i]] = isset($arrayA[$i+1]) ? $arrayA[$i+1] : '';
}

$array = array ('name','1','xixi','php');

$newArr = array_combine (

)
array_filter($array,
    function($key)
    {
        return !($key & 1);
    },ARRAY_FILTER_USE_KEY)
,
array_filter($array,
    function($key)
    {
        return $key & 1;
    },ARRAY_FILTER_USE_KEY)

);
print_r ($newArr);

)
$array = array('name','1','xixi','php'); 
$keyArray = [];
foreach ($array as $k => $v) {
    if ($k%2 == 0) {
        $keyArray[] = $v;
        unset($array[$k]);
    }
}
$res = array_combine($keyArray, $array);

$arr = array('name','1','xixi','php');
while(current($arr)){
    $arr1[current($arr)]='';
    $key = current($arr);
    next($arr);
    $arr1[$key]=current($arr);
    next($arr);
}

<?php
$arr = array('name','1','xixi','php'); 
$chunk = array_chunk($arr,2);
$data  = [];
foreach($chunk as $val){
  $data[] =array($val[0]=>$val[1]);
}
var_dump($data);

all the above answers are correct. I'll make up the train of thought. No, no, no.

array('name','1','xixi','php'); 

if the array is in the form of key,value,key,value, then the remainder equal to 0 through a loop subscript is key, and vice versa is value, and then it is done in a new array

.
 array('name'=>'1','xixi'=>'php');

this format


$array = ['name', '1', 'xixi', 'php'];

$new = [];
foreach ($array as $item => $value) {
    if($item%2!==0){
        $new[$array[$item-1]] = $value;
    }
}

-sharpv2:
$new2 = [];
$len = count($array);
for ($i = 0; $i < $len ; $i += 2) {
    $new2[$array[$i]] = $array[$i+1];
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b37d0b-e613.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b37d0b-e613.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?