0

I am retrieving information from a string, lets call it $data and the output is as follows:

Array
(
    [0] => John Doe
)

How can take the portion of the Full name and set that as a new string, say $fullname

the value of $fullname should be: John Doe

2
  • it ain't a string, it already says on the dump Array, just assign it into another variable, $fullname = $data[0]; Commented Apr 22, 2015 at 11:09
  • If you really mean your string looks like $data = "Array([0] => 'John Doe')", then a look at the following question will probably be useful. Commented Apr 22, 2015 at 11:11

4 Answers 4

3

You need to write $fullname = $data[0].

Since $data is an array.

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

Comments

1

You can directly pass that value within a variable and can easily access it

Lets Say

$data = array('Jon Doe'); // output Array([0] => Jon Doe)

$fullname = $data[0]; // initialized value within $fullname

echo $fullname; // output Jon Doe

Comments

0

It is not a string. It is an array. And you can access array element by its indexes. like -

$data = array(0 => "John Doe");
echo $data[0];

Comments

0

I think you can get the value even without using "=>". Even if that is not used, the system takes "John Doe" as 0th value of that array only. It simply can be,

$data = array("John Doe");
echo $data[0];

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.