Home Backend Development PHP Tutorial php多维数组问题

php多维数组问题

Jun 13, 2016 pm 12:30 PM
array gt tcp

我的多维数组代码如下:

$arr = array(                  
    array('id'=>7363,'fd'=>1,'fb'=>1,'tcp'=>0,'fbdh'=>1,'jxs'=>'GZYX'), 
    array('id'=>7412,'fd'=>1,'fb'=>0,'tcp'=>1,'fbdh'=>1,'jxs'=>'GZYX'), 
    array('id'=>7512,'fd'=>1,'fb'=>1,'tcp'=>0,'fbdh'=>1,'jxs'=>'GZYX'), 
    array('id'=>7516,'fd'=>1,'fb'=>0,'tcp'=>1,'fbdh'=>0,'jxs'=>'BJCJ'), 
); 
  
//意思就是数组里面jxs 相同 他们的fd,fb,tcp,fbdh相加 
//如何把上面数组变成下面的结果 
//结果: 
GZYX 3 2 1 3 
BJCJ 1 0 1 0
Copy after login

----------解决方案------------

<?php 
$arr = array( 
    array('id'=>7363,'fd'=>1,'fb'=>1,'tcp'=>0,'fbdh'=>1,'jxs'=>'GZYX'), 
    array('id'=>7412,'fd'=>1,'fb'=>0,'tcp'=>1,'fbdh'=>1,'jxs'=>'GZYX'), 
    array('id'=>7512,'fd'=>1,'fb'=>1,'tcp'=>0,'fbdh'=>1,'jxs'=>'GZYX'), 
    array('id'=>7516,'fd'=>1,'fb'=>0,'tcp'=>1,'fbdh'=>0,'jxs'=>'BJCJ'), 
); 
  
$result = []; 
foreach ($arr as $a)  { 
    if (empty($result[$a['jxs']])) { 
        $result[$a['jxs']] = $a; 
    } else { 
        foreach ($a as $k => $v) { 
            $result[$a['jxs']][$k] += $v; 
        } 
    } 
} 
  
foreach ($result as $k => $r) { 
    echo sprintf("%s %d %d %d %d\n", 
                 $k, $r['fd'], $r['fb'], $r['tcp'], $r['fbdh']); 
}
Copy after login

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What are the differences between Huawei GT3 Pro and GT4? What are the differences between Huawei GT3 Pro and GT4? Dec 29, 2023 pm 02:27 PM

Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

How to reset tcp/ip protocol in win10? How to reset the tcp/ip protocol stack in windows 10 How to reset tcp/ip protocol in win10? How to reset the tcp/ip protocol stack in windows 10 Mar 16, 2024 am 11:07 AM

How to reset tcp/ip protocol in win10? In fact, the method is very simple. Users can directly enter the command prompt, and then press the ctrl shift enter key combination to perform the operation, or directly execute the reset command to set it up. Let this site do the following. Let us carefully introduce to users how to reset the TCP/IP protocol stack in Windows 10. Method 1 to reset the tcp/ip protocol stack in Windows 10. Administrator permissions 1. We use the shortcut key win R to directly open the run window, then enter cmd and hold down the ctrl shift enter key combination. 2. Or we can directly search for command prompt in the start menu and right-click

How to use TCP to implement conversation between client and server in python How to use TCP to implement conversation between client and server in python May 17, 2023 pm 03:40 PM

TCP client A client sample code that uses the TCP protocol to achieve continuous dialogue: importsocket#Client configuration HOST='localhost'PORT=12345#Create a TCP socket and connect to the server client_socket=socket.socket(socket.AF_INET,socket .SOCK_STREAM)client_socket.connect((HOST,PORT))whileTrue:#Get user input message=input("Please enter the message to be sent:&

See you soon! TCP waves twice, have you seen it? What about the four handshakes? See you soon! TCP waves twice, have you seen it? What about the four handshakes? Jul 24, 2023 pm 05:18 PM

The "connection-oriented" mentioned here means that you need to establish a connection, use the connection, and release the connection. Establishing a connection refers to the well-known TCP three-way handshake. When using a connection, data is transmitted in the form of one send and one confirmation. There is also the release of the connection, which is our common TCP four wave waves.

Fix: Snipping tool not working in Windows 11 Fix: Snipping tool not working in Windows 11 Aug 24, 2023 am 09:48 AM

Why Snipping Tool Not Working on Windows 11 Understanding the root cause of the problem can help find the right solution. Here are the top reasons why the Snipping Tool might not be working properly: Focus Assistant is On: This prevents the Snipping Tool from opening. Corrupted application: If the snipping tool crashes on launch, it might be corrupted. Outdated graphics drivers: Incompatible drivers may interfere with the snipping tool. Interference from other applications: Other running applications may conflict with the Snipping Tool. Certificate has expired: An error during the upgrade process may cause this issu simple solution. These are suitable for most users and do not require any special technical knowledge. 1. Update Windows and Microsoft Store apps

Using Netty4 for TCP communication in Java API development Using Netty4 for TCP communication in Java API development Jun 17, 2023 pm 11:18 PM

TCP is a type of computer network communication protocol and a connection-oriented transmission protocol. In Java application development, TCP communication is widely used in various scenarios, such as data transmission between client and server, real-time transmission of audio and video, etc. Netty4 is a high-performance, highly scalable, and high-performance network programming framework that can optimize the data exchange process between the server and the client to make it more efficient and reliable. The specific implementation steps of using Netty4 for TCP communication are as follows: Introduction

How to send multiple files using a single TCP connection in Java? How to send multiple files using a single TCP connection in Java? Apr 27, 2023 am 08:49 AM

Why is there this blog about using one TCP connection to send multiple files? I have been reading some related things recently. There is no problem in simply using Socket for programming, but this only establishes some basic concepts. Still nothing can be done about the real problem. When I need to transfer files, I find that I seem to have just sent the data (binary data), but some information about the file is lost (the file extension). And each time I can only use one Socket to send one file, there is no way to send files continuously (because I rely on closing the stream to complete sending files, which means that I actually don’t know the length of the file, so I can only send files as one Socket connection represents a file).

Sort array using Array.Sort function in C# Sort array using Array.Sort function in C# Nov 18, 2023 am 10:37 AM

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

See all articles