mary
mary

Reputation: 149

Can i retrieve array value not using loop?

is there a way to retrieve array value not using any loop function? I have this sort of array

$at=array(
    array(
        array('Title:','titl','s','c',$titles),
        array('First Name:','name','i','A',2,10 ),
    ),

Upvotes: 1

Views: 166

Answers (4)

user382538
user382538

Reputation:

you need to know the key of the value you want to select

  echo $at[0];
  echo $at[0][0];
  echo $at[0][3];

Upvotes: 0

Pedro
Pedro

Reputation: 1021

Yes, you can.

for example $at[0], $at[1], $at[2]

When an array hasn't been assigned keys, the keys ( in the above example keys would be 0 1 and 2) ascend numerically from 0.

For an array with keys (such as $at = array('key' => 'value', 'key2' => 'value2') ), you can access the properties as $at['key'], $at['key2'] ( note the quotes wrapping the key name )

Hope this is of use to you!

Cheers!, Pedro

Upvotes: 0

Anush Prem
Anush Prem

Reputation: 1481

try array_values

Sorry this one was suppose to be a comment.

Upvotes: 1

Phil Sturgeon
Phil Sturgeon

Reputation: 30766

Your example looks like it's probably one level too deep, but to directly work with a more basic example:

$at=array( array('Title:','titl','s','c',$titles), array('First Name:','name','i','A',2,10 )

list($title, $something, $foo, $bar) = current($at);

echo $title;

Upvotes: 0

Related Questions