Re: JSON and PHP

Arno Welzel <[email protected]>
Newsgroups comp.lang.php
Message-ID <[email protected]>
The Doctor, 2022-12-28 01:34:

> Trying to implement a JSON array in PHP
> 
> 
> Using
[...]

Can you please reduce such questions this to the relevant part?


[...]
> $myObj = [];
> if (isset($_POST["submit"])){
> (array_push($myObj,[
[...]

Why do you use array_push()? You can just build an array by assigning
values to it:

$myObj['key'] = $value;

[...]
> 'bill_first_name' =>[$_POST['bill_first_name']],

Why do you put an array here?

[$_POST['bill_first_name']] will resolve to a single element array:

'bill_first_name' => [ 'value' ];

Is this really what you want?

[...]
> 	  Just wonder how to supress repeats.

By using correct arrays and not that confusing mixture of values, empty
arrays and single element arrays.


-- 
Arno Welzel
https://arnowelzel.de
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.