6

Possible Duplicate:
Get first element of array
Convert array to string php

I have this array: $ tab.

I perform a print_r() it has just this:

Array ( [0] => integration ).

How to get the value integration without doing $tab[0]?

asked Dec 29, 2011 at 12:54
1
  • 1
    Any reason why you cannot use $tab[0]? Commented Dec 29, 2011 at 12:56

5 Answers 5

5

you could use:

current($tab);
array_shift($tab); // if you don't need to use the array for anything afterwards

Id question why it's in an array in the first place if you don't need it to be and what the issue with using $tab[0] is

answered Dec 29, 2011 at 12:58
1
  • Found this answer on Google! so the problem with using [0] is that you may have a random key name or number after an operation. Commented Jan 20, 2020 at 21:42
1

Well... $tab[0] would probably do what you want. I don't see why you wouldn't want that.

Anyway, getting the string should also be possible with current($tab).

answered Dec 29, 2011 at 12:57
1
list($integration) = $tab;
echo $integration;
//"integration"
answered Dec 29, 2011 at 12:59
0

See here: http://www.ideone.com/R6cRG

$array = array('this is a test');
echo current($array);
answered Dec 29, 2011 at 12:57
0

how about shifting it, like $tab = $tab[0], from which point on you can use just $tab;

Adi
5,1796 gold badges35 silver badges48 bronze badges
answered Dec 29, 2011 at 12:59
1
  • hello guys current does the job. Thanks every body. Commented Dec 29, 2011 at 13:27

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.