私があなたの質問を間違えなかった場合、これを行うことで、最大配列キーを使用して新しい配列を作成できます。
$data = array(
array('userID' => 152, 'email' => 'xxxxx@googlemail.com', 'name' => 'Jay jay go go', 'stream' => 616),
array('userID' => 133, 'email' => 'damxxxxian@indigo.com', 'name' => 'Damian T', 'stream' => 616),
array('userID' => 154, 'email' => 'julie@indigo.com', 'name' => 'Julie1000 E', 'stream' => 615, 'PROGRAMME' => 'Designer'),
array('userID' => 153, 'email' => 'jay@indigo.com', 'name' => 'James1000 G', 'stream' => 616, 'PROGRAMME' => 'Apple Develpepr'),
);
$max_len = null;
$max_arr = null;
// First we find max array to grab its keys
foreach ($data as $i => $a) {
$len = count($a);
if ($max_len === null || $len > $max_len) {
$max_len = $len;
$max_arr = $data[$i];
}
}
$max_arr_keys = array_keys($max_arr);
$data_new = array();
foreach ($data as $i => $a) {
// and using max array keys here
foreach ($max_arr_keys as $k) {
// key exists? get value, or set as NULL
$data_new[$i][$k] = isset($a[$k]) ? $a[$k] : null;
}
}
print_r($data_new);
そして、出力は次のようになります。
Array ( [userID] => 152 [email] => xxxxx@googlemail.com [name] => Jay jay go go [stream] => 616 [PROGRAMME] => null )
Array ( [userID] => 133 [email] => damxxxxian@indigo.com [name] => Damian T [stream] => 616 [PROGRAMME] => null )
Array ( [userID] => 154 [email] => julie@indigo.com [name] => Julie1000 E [stream] => 615 [PROGRAMME] => Designer )
Array ( [userID] => 153 [email] => jay@indigo.com [name] => James1000 G [stream] => 616 [PROGRAMME] => Apple Develpepr )