拆分数组基于密钥的值小数组?

编程入门 行业动态 更新时间:2024-10-23 01:37:35
本文介绍了拆分数组基于密钥的值小数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个关键字搜索MySQL的搜索结果在我的网站正在执行。它们是由会员等级(0-3)进行分类。但是,我需要不同于对方显示的行列 - 像3级变得更突出的格式比其他人。

我想了分裂行到单个阵列。因此,像ARRAY0将包含所有的具有0等级等,然后遍历这些阵列显示结果行。我只是不知道如何做到这一点 - 数组分割成更小的数组。

(仅供参考,我发现这个问题:splitting大阵为更小的阵列基于密钥的名字。,但我真的不知道,如果这就是我需要的东西......也许有些澄清在于q将有助于在这里?)

例如,这里是我的数组:

阵列(     [等级] => 3     [机构] =>测试公司     [imagecompany] => 1636.gif     [公司网址] => www.google     [手机] => 344-433-3424     [传真] =>     [address_on_web] =>物理     [地址] => 2342测试大道     [城市] =>纽约     [stateprov] => WA     [邮政code => 00000     [address_mailing] => 2342测试大道     [city_mailing] =>西雅图     [state_mailing] => WA     [zip_mailing] => 00000     [说明] => 测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试     [客户] => 1636年)

解决方案

您可以使用等级作为重点来创建多维数组是这样的:

$ aRanks =阵列();的foreach($ aArray为$ aEntry){    $ aRanks [$ aEntry ['排名'] [] = $ aEntry;}呼应'< pre>';的print_r($ aRanks);

I have mysql search results from a keyword search being performed on my site. They're sorted by membership rank (0-3). However, I need to display the ranks differently than each other - like rank 3 gets more prominent formatting than the others.

I was thinking of splitting the rows up into individual arrays. So like array0 would contain all the rows that had the rank of 0, etc. Then loop through these arrays to display the results. I just have NO idea how to do this -- split the array up into smaller arrays.

(For reference, I found this question: splitting a large array into smaller arrays based on the key names. but I wasn't really sure if that's what I needed... maybe some clarification on that q would help here?)

For example here is my array:

Array ( [rank] => 3 [organization] => Test Company [imagecompany] => 1636.gif [website] => www.google [phone] => 344-433-3424 [fax] => [address_on_web] => physical [address] => 2342 Test Ave [city] => York [stateprov] => WA [postalcode] => 00000 [address_mailing] => 2342 Test Ave [city_mailing] => Seattle [state_mailing] => WA [zip_mailing] => 00000 [description] => 'Test test Test test Test test Test test Test test Test test Test test Test test Test test Test test Test test Test test Test test Test test Test test' [customerid] => 1636 )

解决方案

You can use the rank as a key to create an multidimensional array like this:

$aRanks = array(); foreach($aArray as $aEntry) { $aRanks[$aEntry['rank']][] = $aEntry; } echo '<pre>'; print_r($aRanks);

更多推荐

拆分数组基于密钥的值小数组?

本文发布于:2023-11-23 01:32:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1619631.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   密钥

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!