search
Homephp教程php手册快速将PHP数组键值组合成字符串

快速将PHP数组键值组合成字符串

Jun 06, 2016 pm 08:08 PM
mvcphpsynthesisstringfastarraykey value

最近在写MVC碰到一个问题:可以使用implode快速将PHP数组组合成字符串。但是如果想要将键值快速输出成字符串呢? 临时想到的方法是循环 假设有一个一维数组$a 存放N个内容. 代码一: ?php$b = '';foreach($a as $key=$value){$b.=$key;}echo $b;? 代码一的写

最近在写MVC碰到一个问题:可以使用implode快速将PHP数组组合成字符串。但是如果想要将键值快速输出成字符串呢?

临时想到的方法是循环

假设有一个一维数组$a 存放N个内容.

代码一:

<?php $b = '';
foreach($a as $key=>$value){
$b.=$key;
}
echo $b;
?>

代码一的写法太痛苦了,而且PHP本身有一个函数implode可以将数组快速组成字符串,那么键值也必定可以的。重新看了一下数组函数的手册,找到array_keys可以直接返还数组中所有键值。手册地址:http://docs.php.net/manual/en/function.array-keys.php

代码二:

<?php echo implode("", array_keys($a));
?>

哈哈,代码是不是简洁多了?:)

Statement
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

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SecLists

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.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor