@ 2016-01-21T06:12:41Z <?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));
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 8.0.0 - 8.0.30 , 8.1.0 - 8.1.28 , 8.2.0 - 8.2.18 , 8.3.0 - 8.3.6 Fatal error: Uncaught Error: Undefined constant "portrait" in /in/j7nVu:25
Stack trace:
#0 /in/j7nVu(35): constructPortrait(Array, Array)
#1 {main}
thrown in /in/j7nVu on line 25
Process exited with code 255 . Output for 7.2.0 - 7.2.33 , 7.3.16 - 7.3.33 , 7.4.0 - 7.4.33 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 - 5.5.38 , 5.6.0 - 5.6.28 , 7.0.0 - 7.0.20 , 7.1.0 - 7.1.20 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"
preferences:dark mode live preview
187.05 ms | 403 KiB | 223 Q