This article is for code sharing. I saw some "big cow" code at work and wanted to share it.
This is specifically, the following two-dimensional array is read from the library.
Code List:
- $user = array(
- 0 => array(
''Id' = & gt; 1, -
E'Name '= & gt; ' Zhang San ',
-
I'email '= & gt; 'zhangsan@sina.com',
- ),
1 => array(
''Id' = & gt; 2, -
- 'name' =>
"
),
2 => - array(
''Id' = & gt; 5,
-
E'Name '= & gt; ' king five ',
with 'email' =>
- ),
…
);
-
-
The above array format is mainly familiar to everyone who has played with PHP+MYSQL.
-
So, now there are two requirements:
- 1) Get the collection of index "id" and save it as a one-bit array, that is, get array(1,2,5)
I don’t know how my friends would write it?
- If it were the way I wrote it in the past, I would directly use foreach, and then use array_push to stuff into array variables one by one. This can also be achieved. But this way of writing affects performance, because using PHP's native functions is definitely more efficient than looping.
Code List:
-
- [php]
- view plain
copy
$ids =
array();