Use of array_merge function
<code><span>$condition</span>[<span>'is_own'</span>] = <span>0</span>; <span>$condition</span>[<span>'is_pass'</span>] = <span>0</span>; <span>$notDeal_user_list</span> = <span>array</span>(); <span>foreach</span>(<span>$temp</span><span>as</span><span>$k</span>=><span>$v</span>){ <span>$condition</span>[<span>'route_id'</span>] = <span>$v</span>[<span>'route_id'</span>]; <span>$temp_array</span> = <span>$route_person_model</span>->where(<span>$condition</span>)->field(<span>'user_id,route_id,id'</span>)->select(); <span>if</span>(!<span>empty</span>(<span>$temp_array</span>)){ <span>$notDeal_user_list</span> = array_merge(<span>$notDeal_user_list</span>,<span>$temp_array</span>); } <span>//array_merge函数 在其中一个为空的时候最后结果为空</span><span>//把不同行程的用户信息都拼接起来</span> } <span>// var_dump($notDeal_user_list); die();</span><span>foreach</span>(<span>$notDeal_user_list</span><span>as</span><span>$k</span>=><span>$v</span>){ <span>$notDeal_user_list</span>[<span>$k</span>][<span>'route_info'</span>] = getRouteInfo(<span>$v</span>[<span>'route_id'</span>]); <span>$notDeal_user_list</span>[<span>$k</span>][<span>'user_info'</span>] = getUserInfo(<span>$v</span>[<span>'user_id'</span>]); } <span>$this</span>->notDeal_user_list = <span>$notDeal_user_list</span>;</code>
在没有加if判断是否为空之前,数组整个都是null,加了之后就OK了。
这个拼接函数在其中一个为空的时候,会整体为空,需要做拼接的判断!
以上就介绍了array_merge 函数的使用,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











List operation //Insert a value from the head of the list. $ret=$redis->lPush('city','guangzhou');//Insert a value from the end of the list. $ret=$redis->rPush('city','guangzhou');//Get the elements in the specified range of the list. 0 represents the first element of the list, -1 represents the last element, and -2 represents the penultimate element. $ret=$redis->l

Title: Example of using the Array.Sort function to sort an array in C# Text: In C#, array is a commonly used data structure, and it is often necessary to sort the array. C# provides the Array class, which has the Sort method to conveniently sort arrays. This article will demonstrate how to use the Array.Sort function in C# to sort an array and provide specific code examples. First, we need to understand the basic usage of the Array.Sort function. Array.So

1: JSONArray to ListJSONArray string to List//Initialize JSONArrayJSONArrayarray=newJSONArray();array.add(0,"a");array.add(1,"b");array.add(2,"c") ;Listlist=JSONObject.parseArray(array.toJSONString(),String.class);System.out.println(list.to

When programming in PHP, we often need to merge arrays. PHP provides the array_merge() function to complete array merging, but when the same key exists in the array, this function will overwrite the original value. In order to solve this problem, PHP also provides an array_merge_recursive() function in the language, which can merge arrays and retain the values of the same keys, making the program design more flexible. array_merge

In PHP, there are many powerful array functions that can make array operations more convenient and faster. When we need to combine two arrays into an associative array, we can use PHP's array_combine function to achieve this operation. This function is actually used to combine the keys of one array as the values of another array into a new associative array. Next, we will explain how to use the array_combine function in PHP to combine two arrays into an associative array. Learn about array_comb

Method to convert list to numpy: 1. Use the numpy.array() function. The first parameter of the function is a list object, which can be a one-dimensional or multi-dimensional list; 2. Use the numpy.asarray() function, which will try its best to Use the data type of the input list; 3. Use the numpy.reshape() function to convert the one-dimensional list into a multi-dimensional NumPy array; 4. Use the numpy.fromiter() function, the first parameter of the function is an iterable object.

Example In this example, we first look at the usage of list.sort() before continuing. Here, we have created a list and sorted it in ascending order using sort() method - #CreatingaListmyList=["Jacob","Harry","Mark","Anthony"]#DisplayingtheListprint("List=",myList)#SorttheListsinAscendingOrdermyList .sort(

How to sort a list using the List.Sort function in C# In the C# programming language, we often need to sort the list. The Sort function of the List class is a powerful tool designed for this purpose. This article will introduce how to use the List.Sort function in C# to sort a list, and provide specific code examples to help readers better understand and apply this function. The List.Sort function is a member function of the List class, used to sort elements in the list. This function receives
