LoginSignup
7
7

More than 5 years have passed since last update.

PHP: 連想配列からキーと値の配列を作る [a=>b,c=>d]から[[a,b],[c,d]]

Posted at
<?php

$assoc = [
    'a' => 1,
    'b' => 2,
    'c' => 3,
];

$array = array_map(function($key, $value){ return [$key, $value]; }, array_keys($assoc), array_values($assoc));

echo json_encode($array);
[["a",1],["b",2],["c",3]]
7
7
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
7