最近在写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)); ?>
哈哈,代码是不是简洁多了?:)
原文地址:快速将PHP数组键值组合成字符串, 感谢原作者分享。

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

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Notepad++7.3.1
Easy-to-use and free code editor

Zend Studio 13.0.1
Powerful PHP integrated development environment

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
The most popular open source editor
