3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $test = array( 'gid'=>1, 'phone_number'=>1, 'weibo'=>1, 'qq'=>1, 'email'=>1, 'gender'=>1, 'age'=>1, 'area'=>1, 'computer'=>1, 'phone'=>1, 'valid_user'=>1, 'bank'=>json_encode(array(1,2,3)), 'tag_big'=>json_encode(array(1,2,3)), 'tag_medium'=>json_encode(array(1,2,3)), 'tag_small'=>json_encode(array(1,2,3)), 'family'=>json_encode(array(1,2,3)), 'friend'=>json_encode(array(1,2,3)), 'visitor'=>json_encode(array(1,2,3)) ); $field = array( 'gid', 'phone_number', 'weibo', 'qq', 'email', 'gender', 'age', 'area', 'computer', 'phone', 'valid_user', 'bank', 'tag_big', 'tag_medium', 'tag_small', 'family', 'friend', 'visitor' ); function constructPortrait($fields, $test){ $retPortraitArr = array(); $portraitArr = array($test); foreach($portraitArr as $key => $portrait){ foreach($fields as $field){ var_dump($fields, portrait);exit; $retPortraitArr[$key][$field] = isset($portrait[$key]) && !empty($portrait[$key]) ? $portrait[$key] : ''; } } return $retPortraitArr; } echo json_encode(constructPortrait($field, $test));
based on EeCCN
Output for 7.2.0
Warning: Use of undefined constant portrait - assumed 'portrait' (this will throw an Error in a future version of PHP) in /in/j7nVu on line 25 array(18) { [0]=> string(3) "gid" [1]=> string(12) "phone_number" [2]=> string(5) "weibo" [3]=> string(2) "qq" [4]=> string(5) "email" [5]=> string(6) "gender" [6]=> string(3) "age" [7]=> string(4) "area" [8]=> string(8) "computer" [9]=> string(5) "phone" [10]=> string(10) "valid_user" [11]=> string(4) "bank" [12]=> string(7) "tag_big" [13]=> string(10) "tag_medium" [14]=> string(9) "tag_small" [15]=> string(6) "family" [16]=> string(6) "friend" [17]=> string(7) "visitor" } string(8) "portrait"
Output for 5.5.0 - 7.1.10
Notice: Use of undefined constant portrait - assumed 'portrait' in /in/j7nVu on line 25 array(18) { [0]=> string(3) "gid" [1]=> string(12) "phone_number" [2]=> string(5) "weibo" [3]=> string(2) "qq" [4]=> string(5) "email" [5]=> string(6) "gender" [6]=> string(3) "age" [7]=> string(4) "area" [8]=> string(8) "computer" [9]=> string(5) "phone" [10]=> string(10) "valid_user" [11]=> string(4) "bank" [12]=> string(7) "tag_big" [13]=> string(10) "tag_medium" [14]=> string(9) "tag_small" [15]=> string(6) "family" [16]=> string(6) "friend" [17]=> string(7) "visitor" } string(8) "portrait"