- 함수 array_2d_to_1d()
1 PHP[ | ]
PHP
Copy
function array_2d_to_1d( $arr ) {
$keys = array();
$values = array();
foreach( $arr as $k => $v ) {
if( is_array($v) ) foreach( $v as $k2 => $v2 ) {
$keys[] = $k."[$k2]";
$values[] = $v2;
}
else {
$keys[] = $k;
$values[] = $v;
}
}
return array_combine($keys, $values);
}
$arr = array(
'response' => 'json',
'command' => 'greet',
'type' => 'sayhello',
'friends' => array(
'0' => 'Alice',
'1' => 'Bob',
'2' => 'Carol',
),
);
print_r( array_2d_to_1d($arr) );
# Array
# (
# [response] => json
# [command] => greet
# [type] => sayhello
# [friends[0]] => Alice
# [friends[1]] => Bob
# [friends[2]] => Carol
# )
2 같이 보기[ | ]
편집자 Jmnote Jmnote bot
로그인하시면 댓글을 쓸 수 있습니다.
- 분류 댓글:
- PHP (8)
PHP 파일 다운로드 구현 2 (한글 파일명 지원) ― …PHP에서 오라클 DB 사용 ― YoWuPHP 파일 업로드 구현 ― 일리단사오육칠PHP 파일 업로드 구현 ― JmnotePHP 파일 다운로드 구현 2 (한글 파일명 지원) ― AnmkstLib my.php ― 신정섭Lib my.php ― Jmnote로또번호 생성 ―Pinkcrimson