1

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 ),
    ),
4
  • first one can be accessed via $at[0][0], et cetera Commented Dec 21, 2010 at 11:43
  • You mean $at[0], or $at[0][0]? I don't understand the question. Commented Dec 21, 2010 at 11:43
  • Can you tell me how you want the output to be.? Commented Dec 21, 2010 at 11:46
  • function work($s){ global $at;foreach($at[$s] as $v){echo $v[1];} via this code i can get the whole values out of $at and can use $v[1] in my switch and anyother function i need but now i want to have this whole list of array values like (title name and so on) without using foreach loop i cannot use $at[1][0] as i have a long bunch of array Commented Dec 21, 2010 at 13:38

4 Answers 4

1

try array_values

Sorry this one was suppose to be a comment.

Sign up to request clarification or add additional context in comments.

Comments

0

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;

Comments

0

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

1 Comment

function work($s){ global $at;foreach($at[$s] as $v){echo $v[1];} via this code i can get the whole values out of $at and can use $v[1] in my switch and anyother function i need but now i want to have this whole list of array values like (title name and so on) without using foreach loop i cannot use $at[1][0] as i have a long bunch of array
0

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.