English 中文(简体)
PHP: 在一个阵列中使用一个价值阵列的阵列获得价值
原标题:PHP: Using a string address of a value in an array get the value

I have a person array, with a key n for name. The value for n is an array, with key l (short for last ) having the value I want to get at, the last name.

出于奇怪的方案拟订原因,我用最后名称“地址”作为string

How do I do this?
I ve tried eval, among others.

共和国 我是清楚的!

我想要的是利用变数的测试获得。

例如:

$person[$test]

(显然没有工作,但又做了些什么?)

。 例如,有时会有<条码>[][居民][街道]

<?php

    $test = "[ n ][ l ]";

    echo "I ve got a string with the array index ".$test. "
";

    $person = array("n"=>array( l => SMITH ));

    echo  the array, $person, is this:  ."
";
    print_r($person);

    echo "What I want is ".$person[ n ][ l ]. "
";
    ?>

Output:

I ve got a string with the array index [ n ][ l ]
the array, $person, is this: 

    Array
    (
        [n] => Array
            (
                [l] => SMITH
            )

    )

我想的是SMITH。

最佳回答
问题回答

我看不出有任何合理理由在此案中使用阵列,你只会使你的编码生活复杂化。 你们需要学习的是面向目标的方案拟订。

Then you would only have to create a People object that would contain an array of Person objects.

在最简单的表格中,一个人的名字只能用一个人的名字。

People->listOfPersons[0]->fullName->familyName 

or even better with getters and setters :

People->getNextPerson()->getFamilyName()
$index1 = $test[2];    
$index2 = $test[7];

echo $person[$index1][$index2];




相关问题
Simple JAVA: Password Verifier problem

I have a simple problem that says: A password for xyz corporation is supposed to be 6 characters long and made up of a combination of letters and digits. Write a program fragment to read in a string ...

Case insensitive comparison of strings in shell script

The == operator is used to compare two strings in shell script. However, I want to compare two strings ignoring case, how can it be done? Is there any standard command for this?

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

String initialization with pair of iterators

I m trying to initialize string with iterators and something like this works: ifstream fin("tmp.txt"); istream_iterator<char> in_i(fin), eos; //here eos is 1 over the end string s(in_i, ...

break a string in parts

I have a string "pc1|pc2|pc3|" I want to get each word on different line like: pc1 pc2 pc3 I need to do this in C#... any suggestions??

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...

热门标签