How to increase the key value of php two-dimensional array
This article mainly shows you the "php two-dimensional array how to increase the key value", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "php two-dimensional array how to increase key value" this article.
Php two-dimensional array to increase the key value method: 1, create a PHP example file; 2, through the "foreach ($listening_collect as $key = > $value) {.}" method to add key value to the two-dimensional array.
This article operating environment: windows7 system, PHP7.1 version, DELL G3 computer
Php array loop to add key-value pairs
Two-dimensional array addition method:
The loop $listening_collect is a two-dimensional array to which you add a you_answer element
$listening_collect = $this- > ser_toefllistening- > zt_collect ($listening_articleid)-> result_array (); foreach ($listening_collect as $key = > $value) {/ / variable value $answer is an array of elements $answer = $this- > ser_toefllistening- > answer ($value ['id'], $u_id); $listening_collect [$key] [' you_answer'] = $answer ['answer'];}
Print the $listening_collect array
Print the $listening_collect array after adding
One-dimensional array addition method:
/ / this is an one-dimensional array to add foreach ($arr as $key = > & $vo) {$vo ['name'] =' star'; $vo ['age'] =' 24star';} $arr [$key] ['name'] =' star'; $arr [$key] ['age'] =' 24'
-
$res = Db::name ('ht_let_go')-> where ("title", "like", "% $name%")-> order (' id desc')-> paginate ($size,false, ['page'= > $page,'query'= > request ()-> param ()])-> toArray () Foreach ($res ['data'] as $k = > $v) {$res [' data'] [$k] ['sum_num'] = Db::name (' ht_let_go_buy')-> where ('let_go_id',$v [' id'])-> count ();} dump ($res); die
The above is all the content of the article "how to increase the key value of php two-dimensional array". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!