0

i'm trying to insert an implode generated string to an array that then later be used for json implementation

the implode generated string is look like this

'id' => $this->_SqlResult[0],'UserId' => $this->_SqlResult[1],'Msg' => $this->_SqlResult[2],'MsgStamp' => $this->_SqlResult[3]

i would like to used it in this code

$this->_JsonArr[]=array($Generated string);

to achieve something like this

 $this->_JsonArr[]=array('id' => $this->_SqlResult[0],'UserId' => $this->_SqlResult[1],'Msg' => $this->_SqlResult[2],'MsgStamp' => $this->_SqlResult[3]);

instead i got something like this

 $this->_JsonArr[]=array(" 'id' => $this->_SqlResult[0],'UserId' => $this->_SqlResult[1],'Msg' => $this->_SqlResult[2],'MsgStamp' => $this->_SqlResult[3]");

seem like generated string is treated as one element as key and value pair. obviously i can get expected output from mysql because of this, can anybody help me with this

2 Answers 2

1

Why do you need to implode anything? Just pass the array:

$this->_JsonArr[] = your-non-imploded-array-here;

I think a full solution to what you want to do is something like this (i.e., the third code box in your question):

$row = array(
  'id' => $this->_SqlResult[0],
  'UserId' => $this->_SqlResult[1],
  'Msg' => $this->_SqlResult[2],
  'MsgStamp' => $this->_SqlResult[3]
);
$this->_JsonArr[] = $row;
Sign up to request clarification or add additional context in comments.

1 Comment

I think (just wild guess) OP got confused when serving data in json (hence imploding the array into string). So, as addition @zul don't forget to echo json_encode($this->_JsonArr) to output the string with data.
0

$this->_JsonArr[]=array($Generated string);

Looks like you want use arrays keys and values, but as I see you put into array plain string with expectation that array parse your plain string in format: keys => values.

You can try create array like below:

$this->_JsonArr[ $Generated_key ] = array( $Generated_value );

(Please correct me if I wrong understand your question).

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.