$t1 = Array ( 0 => '南昌', 1 => '南昌', 2 => '赣州', 3 => '九江', 4 => '赣州', 5 => '九江');
$t2 = Array ( 0 => '优秀', 1 => '良好', 2 => '优秀', 3 => '良好', 4 => '优秀', 5 => '差等' );
比如,我有上面两个数组。$t1【0】和$t2【0】....$t1【i】和$t2【i】是有对应关系的,$t1【0】和$t2【0】代表=====南昌,优秀。
我想把$t1去重形成一个新的数组$t11 = Array ( 0 => '南昌', 1 => '赣州', 2 => '九江');
同时对$t2进行拆分。形成三个新的数组(分别统计$t11数组对应的优秀、良好、差等)。分别和$t11关联。
南昌,赣州 九江优秀的数目统计。(根据$t2去计算优良差的个数)
优秀的数组如下
$t2_yx=Array ( 0 => '1', 1 => '2', 2 => '0' );
良好的数组如下
$t2_lh=Array ( 0 => '1', 1 => '0', 2 => '1' );
差等的数组如下
$t2_cd=Array ( 0 => '0', 1 => '0', 2 => '1' );
请问用程序什么实现。。感谢。
回复讨论(解决方案)
//第一步$t1 = Array ( 0 => '南昌', 1 => '南昌', 2 => '赣州', 3 => '九江', 4 => '赣州', 5 => '九江'); $t2 = Array ( 0 => '优秀', 1 => '良好', 2 => '优秀', 3 => '良好', 4 => '优秀', 5 => '差等' );$t = array_map(null, $t1, $t2);print_r($t);/* 得到Array( [0] => Array ( [0] => 南昌 [1] => 优秀 ) [1] => Array ( [0] => 南昌 [1] => 良好 ) [2] => Array ( [0] => 赣州 [1] => 优秀 ) [3] => Array ( [0] => 九江 [1] => 良好 ) [4] => Array ( [0] => 赣州 [1] => 优秀 ) [5] => Array ( [0] => 九江 [1] => 差等 ))*///第二步$r = array();foreach($t as $v) { $r[$v[0]][] = $v[1];}print_r($r);/*得到Array( [南昌] => Array ( [0] => 优秀 [1] => 良好 ) [赣州] => Array ( [0] => 优秀 [1] => 优秀 ) [九江] => Array ( [0] => 良好 [1] => 差等 ))*///第三步$r = array_map('array_count_values', $r);print_r($r);/*得到Array( [南昌] => Array ( [优秀] => 1 [良好] => 1 ) [赣州] => Array ( [优秀] => 2 ) [九江] => Array ( [良好] => 1 [差等] => 1 ))
接下来就不用说了
接下来就不用说了
请高人指点咯。还是不太清楚。
//第一步$t1 = Array ( 0 => '南昌', 1 => '南昌', 2 => '赣州', 3 => '九江', 4 => '赣州', 5 => '九江'); $t2 = Array ( 0 => '优秀', 1 => '良好', 2 => '优秀', 3 => '良好', 4 => '优秀', 5 => '差等' );$t = array_map(null, $t1, $t2);print_r($t);/* 得到Array( [0] => Array ( [0] => 南昌 [1] => 优秀 ) [1] => Array ( [0] => 南昌 [1] => 良好 ) [2] => Array ( [0] => 赣州 [1] => 优秀 ) [3] => Array ( [0] => 九江 [1] => 良好 ) [4] => Array ( [0] => 赣州 [1] => 优秀 ) [5] => Array ( [0] => 九江 [1] => 差等 ))*///第二步$r = array();foreach($t as $v) { $r[$v[0]][] = $v[1];}print_r($r);/*得到Array( [南昌] => Array ( [0] => 优秀 [1] => 良好 ) [赣州] => Array ( [0] => 优秀 [1] => 优秀 ) [九江] => Array ( [0] => 良好 [1] => 差等 ))*///第三步$r = array_map('array_count_values', $r);print_r($r);/*得到Array( [南昌] => Array ( [优秀] => 1 [良好] => 1 ) [赣州] => Array ( [优秀] => 2 ) [九江] => Array ( [良好] => 1 [差等] => 1 ))
接下来就不用说了
请高人说完。。谢谢了。
请高人说完。。谢谢了。
其实说的够明显了,稍微改一下代码
$t1 = Array ( 0 => '南昌', 1 => '南昌', 2 => '赣州', 3 => '九江', 4 => '赣州', 5 => '九江'); $t2 = Array ( 0 => '优秀', 1 => '良好', 2 => '优秀', 3 => '良好', 4 => '优秀', 5 => '差等' ); $t = array_map(null, $t1, $t2); $r = array(); foreach($t as $v) { $r[$v[1]][] = $v[0]; } $r = array_map('array_count_values', $r); dump($r);//--------------------------------array(3) { ["优秀"] => array(2) { ["南昌"] => int(1) ["赣州"] => int(2) } ["良好"] => array(2) { ["南昌"] => int(1) ["九江"] => int(1) } ["差等"] => array(1) { ["九江"] => int(1) }}
换种显示方式总该可以了吧。

Effective methods to prevent session fixed attacks include: 1. Regenerate the session ID after the user logs in; 2. Use a secure session ID generation algorithm; 3. Implement the session timeout mechanism; 4. Encrypt session data using HTTPS. These measures can ensure that the application is indestructible when facing session fixed attacks.

Implementing session-free authentication can be achieved by using JSONWebTokens (JWT), a token-based authentication system where all necessary information is stored in the token without server-side session storage. 1) Use JWT to generate and verify tokens, 2) Ensure that HTTPS is used to prevent tokens from being intercepted, 3) Securely store tokens on the client side, 4) Verify tokens on the server side to prevent tampering, 5) Implement token revocation mechanisms, such as using short-term access tokens and long-term refresh tokens.

The security risks of PHP sessions mainly include session hijacking, session fixation, session prediction and session poisoning. 1. Session hijacking can be prevented by using HTTPS and protecting cookies. 2. Session fixation can be avoided by regenerating the session ID before the user logs in. 3. Session prediction needs to ensure the randomness and unpredictability of session IDs. 4. Session poisoning can be prevented by verifying and filtering session data.

To destroy a PHP session, you need to start the session first, then clear the data and destroy the session file. 1. Use session_start() to start the session. 2. Use session_unset() to clear the session data. 3. Finally, use session_destroy() to destroy the session file to ensure data security and resource release.

How to change the default session saving path of PHP? It can be achieved through the following steps: use session_save_path('/var/www/sessions');session_start(); in PHP scripts to set the session saving path. Set session.save_path="/var/www/sessions" in the php.ini file to change the session saving path globally. Use Memcached or Redis to store session data, such as ini_set('session.save_handler','memcached'); ini_set(

TomodifydatainaPHPsession,startthesessionwithsession_start(),thenuse$_SESSIONtoset,modify,orremovevariables.1)Startthesession.2)Setormodifysessionvariablesusing$_SESSION.3)Removevariableswithunset().4)Clearallvariableswithsession_unset().5)Destroythe

Arrays can be stored in PHP sessions. 1. Start the session and use session_start(). 2. Create an array and store it in $_SESSION. 3. Retrieve the array through $_SESSION. 4. Optimize session data to improve performance.

PHP session garbage collection is triggered through a probability mechanism to clean up expired session data. 1) Set the trigger probability and session life cycle in the configuration file; 2) You can use cron tasks to optimize high-load applications; 3) You need to balance the garbage collection frequency and performance to avoid data loss.


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

SublimeText3 Chinese version
Chinese version, very easy to use

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 Linux new version
SublimeText3 Linux latest version

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
