Re: JSON and PHP

H H H H H H H H H H H H H H H H H H E <[email protected]>
Newsgroups comp.lang.php
Message-ID <[email protected]>
Hey, can U help me ------> https://groups.google.com/g/magic/c/CRDqi-wyQJU


?


Please help...



On Wednesday, December 28, 2022 at 11:09:15 PM UTC+2, J.O. Aho wrote:
> On 28/12/2022 15.42, The Doctor wrote: 
> > In article <[email protected]>, 
> > J.O. Aho <[email protected]> wrote: 
> >> On 28/12/2022 01.34, The Doctor wrote: 
> >>> Trying to implement a JSON array in PHP 
> >>> Using 
> >> 
> >> <too much code so removed, use a code repository and link to it> 
> >> 
> >>> Just wonder how to supress repeats. 
> >> 
> >> Don't insert the same data multiple times into an array. 
> >> 
> >> Here is a short code demonstrating what you are doing 
> >> --- example.php --- 
> >> <?PHP 
> >> for($i = 0; $i < 3; $i++) { // this replaces the foreach in the original 
> >> code 
> >> $MyObj[] = array("same each time", "this from round $i"); 
> >> var_dump($MyObj); 
> >> } 
> >> ?> 
> >> --- eof --- 
> >> 
> >> You can see how the array grows each iteration of the loop. 
> >> 
> > 
> > Just that we are converting from php to php/json.
> The issue ain't related to the conversion, it's you logic that is flawed.
> > Further, the foreach is due to a line that is coming is from 
> > a previous session being passed on.
> But it's your foreach loop that makes you to have duplicates in your 
> example in the same way as in the small example file. Take some time and 
> think about what happens in each iteration, when you know what "$MyObj[] 
> =" means, then you can make the proper changes in your own code. 
> 
> I would also think you could simplify the whole thing for example a lot 
> of the data is static, just set that data once not each time in a 
> foreach loop and also as Arno already pointed out, don't add a single 
> value as an array, you just make things more complex than they need to be. 
> 
> Remember to not use input type="hidden" for information a user already 
> have posted to you, those goes into the session, the only thing would be 
> an identifier that is unique for this transaction. Prices you should 
> never take from post values, only the amount of items, for if you start 
> trust the posted values, I will be able to buy everything you have for 0 
> bucks. 
> 
> -- 
> //Aho
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.