Home Backend Development PHP Tutorial 回到给定索引的值

回到给定索引的值

Jun 13, 2016 pm 12:18 PM
apple array BANANA gt nbsp

返回给定索引的值
请问下,PHP是否存在这样的数组函数

已知数组
$a['a']=>'apple',$a['b']=>'banana,$a['p']=>'pear'

已知某个数组
$key = array('a','b','p');

获得对应数组$a的值,并得到数组如下
$val = array('apple','banana','pear');
------解决思路----------------------

$a = array('a' => 'apple', 'b' => 'banana', 'p' => 'pear');<br />$key = array('a','b','p');<br />foreach($key as $k) $val[] = $a[$k];<br /><br />print_r($val);
Copy after login
Array<br />(<br />    [0] => apple<br />    [1] => banana<br />    [2] => pear<br />)<br /><br />
Copy after login

------解决思路----------------------
<br />$a = array(<br />  'a'=>'apple',<br />  'b'=>'banana',<br />  'p'=>'pear'<br />);<br /><br />$key = array('a','b','p');<br /><br />$val = array();<br /><br />foreach($key as $v){<br />    array_push($val, $a[$v]);<br />}<br /><br />print_r($val);<br />
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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

Apple\'s \'HomeAccessory\' device revealed to have an A18 chipset among other features Apple\'s \'HomeAccessory\' device revealed to have an A18 chipset among other features Sep 27, 2024 am 09:02 AM

Fresh details of Apple's HomePod-like device with an integrated screen have surfaced and they paint a clearer picture of the device which has been referred to as 'HomeAccessory'. When it launches, it will be Apple's answer to Google's Nest Hub Max an

Update | Hacker explains how to install Epic Games Store and Fortnite on iPad outside the EU Update | Hacker explains how to install Epic Games Store and Fortnite on iPad outside the EU Aug 18, 2024 am 06:34 AM

Update: Saunders Tech has uploaded a tutorial to his YouTube channel (video embedded below) explaining how to install Fortnite and the Epic Games Store on an iPad outside the EU. However, not only does the process require specific beta versions of iO

iPhone 16 Pro and iPhone 16 Pro Max official with new cameras, A18 Pro SoC and larger screens iPhone 16 Pro and iPhone 16 Pro Max official with new cameras, A18 Pro SoC and larger screens Sep 10, 2024 am 06:50 AM

Apple has finally lifted the covers off its new high-end iPhone models. The iPhone 16 Pro and iPhone 16 Pro Max now come with larger screens compared to their last-gen counterparts (6.3-in on the Pro, 6.9-in on Pro Max). They get an enhanced Apple A1

Apple iPhone 16 and iPhone 16 Plus launched with 48MP \'Fusion camera\', Camera Control and A18 chip Apple iPhone 16 and iPhone 16 Plus launched with 48MP \'Fusion camera\', Camera Control and A18 chip Sep 10, 2024 am 09:30 AM

Apple has officially announced the iPhone 16 and iPhone 16 Plus, introducing key hardware updates with the new A18 chip. Both models come in two sizes—6.1 inches and 6.7 inches—with Super Retina XDR displays. They also feature aluminum designs and ar

Apple analyst offers new insights into upcoming iPhone 16, iPhone SE 4 and even rumoured iPhone 17 Air releases Apple analyst offers new insights into upcoming iPhone 16, iPhone SE 4 and even rumoured iPhone 17 Air releases Aug 12, 2024 pm 10:01 PM

Apple's next-generation iPhones are right around the corner. While the company has not shared the date of a new launch event yet, all signs appear to point to a September release, just like last year's iPhone 15 series. Incidentally, footage of dummy

iOS 18 beta now supports Adaptive Lighting on Matter smart bulbs iOS 18 beta now supports Adaptive Lighting on Matter smart bulbs Aug 14, 2024 pm 12:48 PM

In addition to the generative AI features plannedfor iOS 18, several Reddit users have discovered that the iOS 18.1 beta enables Adaptive Lighting by default for Nanoleaf’s Matter-compatible smart bulbs. Adaptive Lightning, a staple of Apple Home sin

New Apple iPhone 16 design and colours shown in comparison video against iPhone 15 New Apple iPhone 16 design and colours shown in comparison video against iPhone 15 Aug 12, 2024 am 06:59 AM

The launches of Apple's next iPhones are not expected for at least another month. Nonetheless, footage showing dummy iPhone 16 units in what are said to be official launch colours continues to emerge online. Incidentally, while Google previously rele

iPhone parts Activation Lock spotted in iOS 18 RC — may be Apple\'s latest blow to right to repair sold under the guise of user protection iPhone parts Activation Lock spotted in iOS 18 RC — may be Apple\'s latest blow to right to repair sold under the guise of user protection Sep 14, 2024 am 06:29 AM

Earlier this year, Apple announced that it would be expanding its Activation Lock feature to iPhone components. This effectively links individual iPhone components, like the battery, display, FaceID assembly, and camera hardware to an iCloud account,

See all articles