0

This is my data

Array 
(
    [t] => Array
        (
            [0] => SS
        )

    [size] => Array
        (
            [0] => 85
        )
)

result should be

[t] => Array
    (
        [0] => SS
    )

[size] => Array
    (
        [0] => 85
    )
2
  • 1
    Looks like this is the first index of main array... I mean content. Commented Sep 26, 2016 at 10:40
  • If you do a print_r($your_arr), Dont you get the result you need? without making any change? Commented Sep 26, 2016 at 10:43

5 Answers 5

3

use extract function

extract(
    Array(
        't' => Array(0 => SS),
        'size' => Array(0 => 85)
    )
);

print_r($t);    //  Array ( [0] => SS )
print_r($size); //  Array ( [0] => 85 ) 
Sign up to request clarification or add additional context in comments.

1 Comment

here t and size is not static
3

Use the list function to set them to variables.

$data = array_values(array(
    't' => array('SS'),
    'size' => array(85)
));

list($t, $size) = $data;

Edit: Add array_values as the old solution produces Undefined index warnings.

print_r($t); //array(0 => 'SS')
print_r($size); //array(0 => 85)

Comments

1

Just do :

$myVariable[0] 

if your array is contained in variable called $myVariable

Comments

1

use current:

 $array = current($array);

Comments

0

Let original array is $array then

 $array = $array[0]

will give you what you want.

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.