寻找Java的Map和List的PHP等价物? [英] searching for PHP equivalent for Java's Map and List?

查看:213
本文介绍了寻找Java的Map和List的PHP等价物?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java案例#1中:

In Java case#1:

Map m1 = new LinkedHashMap();
List l1 = new LinkedList();
m1.put("key1","val1");
m1.put("key2","val2");
l1.add(m1);

在java案例#2

List l1 = new LinkedList();
l1.add("val1");
l1.add("val2");
l1.add("val3");

这些情况在PHP中有什么?

What's about in PHP for these cases ?

推荐答案

在PHP中,数组作为所有类型的容器。它们可以用作地图,列表和集合。

In PHP, arrays serve as all types of containers. They can be used as maps, lists and sets.

通过重置提供链接列表功能 / 分组 / 电流 / / 函数;看看文档的参见部分,以确保不会错过任何一个。

Linked list functionality is provided through the reset/prev/current/next/end functions; have a look at the "see also" section of the docs to make sure you don't miss any of them.

对于地图功能,您只需直接索引到数组;但请记住,PHP中的数组键只能为字符串或整数,并且大部分时间在同一数组中混合不是正确的事情(尽管没有技术原因不是,有些情况是有意义的)。

For map functionality you just index into the array directly; but keep in mind that array keys in PHP can only be strings or integers, and also that most of the time mixing both in the same array is not the right thing to do (although there is no technical reason not to, and there are cases where it makes sense).

SPL提供 SplDoublyLinkedList 类,但没有任何一个简单的数组不会给你。

SPL provides the SplDoublyLinkedList class, but there's nothing in there that a simple array doesn't also give you.

这篇关于寻找Java的Map和List的PHP等价物?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆