您的位置:

php数组如何重组,php初始化数组

本文目录一览:

php复杂数组如何重组

$arr = array(

array('fid'=85,'fup'=23,'type'='sub'),

array('fid'=66,'fup'=3,'type'='sub'),

array('fid'=188,'fup'=2,'type'='sub'),

array('fid'=57,'fup'=41,'type'='gro'),

array('fid'=35,'fup'=98,'type'='wc'),

array('fid'=54,'fup'=22,'type'='bfo'),

);

$result = array();

foreach($arr as $k=$v){

if($v['type']=='sub'){

$result[$v['fid']] = $v;

}

}

print_r($result);

这样既可。

php数组重组

是固定的么?

?php

$a = array('0' = array('id' = 151,'name'='leo'),

           '1' = array('id' = 120,'name'='john'),

           '2' = array('id' = 153,'name'='hello'),

           '3' = array('id' = 118,'name'='word'),

        );

foreach($a as $k = $v){

    if($v['id']==151 || $v['id']==120){

        $b['0'][] = $a[$k];

    }else{

        $b['1'][] = $a[$k];

    }

    

}

var_dump($b);

如何将 php 二维数组重组

?php

$a=array(

  0 = array(

    "yw" ="85",

    "sx" ="97",

    "yy" ="100"

  ),

  1= array(

    "yw"= "85.5",

    "sx" =  "96",

    "yy"=  "96"

  ),

  2= array(

    "yw" = "84.5",

    "sx" =  "90",

    "yy" =  "98",

  )

);

$f=array();

foreach($a as $b=$c){

foreach($c as $d=$e){

$f[$d][]=$e;

}

}

echo 'pre/';

print_r($f);

?

php 数组分割重组

?php

$arr = array(

array("title"="w15","url"="l2","url2"="width","value"="3.2"),

array("title"="w15","url"="l3","url2"="width","value"="3.1"),

array("title"="w15","url"="l4","url2"="width","value"="3.0"),

array("title"="w15","url"="l5","url2"="width","value"="3.1"),

array("title"="w15","url"="l6","url2"="width","value"="3.4"),

array("title"="w16","url"="l8","url2"="width","value"="3.8"),

array("title"="w16","url"="l9","url2"="width","value"="3.9")

);

$new_arr = array();

foreach($arr as $item) {

$k = $item['title'];

if(!isset($new_arr[$k])) {

$new_arr[$k] = array(

'title' = $k,

'url' = array($item['url']),

'url2' = array($item['url']),

'value' = array($item['value'])

);

} else {

$new_arr[$k]['url'][] = $item['url'];

$new_arr[$k]['url2'][] = $item['url2'];

$new_arr[$k]['value'][] = $item['value'];

}

}

//print_r($new_arr); // 如果用 title 做 key, 到这儿就可以了

$new_arr = array_values($new_arr);

print_r($new_arr);