user3436467
user3436467

Reputation: 1775

Extract data from string and set as new string

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

Upvotes: 0

Views: 43

Answers (4)

Mekap
Mekap

Reputation: 2085

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

Since $data is an array.

Upvotes: 3

user4819055
user4819055

Reputation:

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

Upvotes: 1

Naga Naveen
Naga Naveen

Reputation: 99

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];

Upvotes: 0

Sougata Bose
Sougata Bose

Reputation: 31749

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];

Upvotes: 0

Related Questions