0

I try to make an array, this is my code,

$sosd='"tokn"=>"123", "grnn"=>"GRN/15/08/0001"';

$ardt=array($sosd);

$tken=$ardt['tokn'];

But cant get data in line 3

error is Array to string conversion in D:\xampp\htdocs\myebus_dms\grn_edit.php on line 3 Array

pls hel me to solve this problum.

1
  • Yeah. It's not an array. it's a string. Commented Sep 4, 2015 at 4:33

2 Answers 2

1

What you were doing over here is making an array of the following string

$sosd='"tokn"=>"123", "grnn"=>"GRN/15/08/0001"';

So when you write it as

$ardt=array($sosd);

And if you try using print_r then you'll get to know that it generates an array like as

Array
(
    [0] => "tokn"=>"123", "grnn"=>"GRN/15/08/0001"
)

and not as you were expecting over here like as

Array
(
    [tokn] => 123
    [grnn] => GRN/15/08/0001
)

So in order to achieve an array instead you can simply make an array as

$sosd=["tokn"=>"123", "grnn"=>"GRN/15/08/0001"]; //>PHP 5.4
$tken = $sosd['tokn']; 
Sign up to request clarification or add additional context in comments.

Comments

0

You didn't declare the array correctly. you should declare it like this

$sosd=["tokn"=>"123", "grnn"=>"GRN/15/08/0001"];

or

$sosd=array("tokn"=>"123", "grnn"=>"GRN/15/08/0001");

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.