Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #19317
| From | Arno Welzel <usenet@arnowelzel.de> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: Stripping a JSON of extra characters in PHP |
| Date | 2023-02-09 20:22 +0100 |
| Message-ID | <k4kvg1F6414U1@mid.individual.net> (permalink) |
| References | <tre1ei$2lti$75@gallifrey.nk.ca> <trs9fn$ak$1@gallifrey.nk.ca> <k4efniF59f9U2@mid.individual.net> <k4egigF59f9U3@mid.individual.net> <trtt6f$19ol$39@gallifrey.nk.ca> |
The Doctor, 2023-02-07 17:10:
> In article <k4egigF59f9U3@mid.individual.net>,
> Arno Welzel <usenet@arnowelzel.de> wrote:
[...]
>> Hopefully you understand the idea now - if you don't want an ARRAY in
>> the JSON then do not create one! If the specification asks for an OBJECT
>> then use an OBJECT based on a class with named members.
>>
>
> But The information is being pulled from a pre-filled hence you need,
> Something like
So what? You can also create objects based on "pre-filled" data.
> //$items=array(
> if (isset($_POST["submit"])){
>
> foreach ($_POST['quantity'] as $key => $value) {
> if( $value > 0){
> if(isset($_POST['with_gst'][$key])){
> $unit_cost = 63.00;
> }else{
> $unit_cost = 60.00; //no gst included
> }
> $newsubtotal = ($unit_cost * $value);
> $quantity = ($value);
> $itemssubarray[]= array(
CREATE AN OBJECT HERE!
First define a class for this above all the code:
class CartItem
{
public $url;
public $description;
public $product_code;
public $unit_cost;
public $quantity;
}
And then use THIS(!) to create the OBJECT(!) for it:
$item = new Item();
$item->url = "https://www.pdsolutions.ca/images/newwhiteheader.png";
$item->description = $_POST['description'][$key];
$item->product_code = $_POST['id'][$key];
$item->unit_cost = $unit_cost;
$item->quantity = $quantity;
$itemssubarray[] = $item;
[...]
> $cartarray[] = array(
> "cart"=>array( $items
> ),
NO! Create an OBJECT!
> 'subtotal' => $subtotal,
> "tax"=>array(
> 'amount' => ($subtotal * 0.05),
> 'description' => "GST",
> 'rate' => "5.00",
> ),
> );
Sorry - but if you are really not able to understand what I write, you
should pay someone to do the job for you.
--
Arno Welzel
https://arnowelzel.de
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar
Stripping a JSON of extra characters in PHP doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-02-01 15:45 +0000
Re: Stripping a JSON of extra characters in PHP Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-02-01 16:09 +0000
Re: Stripping a JSON of extra characters in PHP Arno Welzel <usenet@arnowelzel.de> - 2023-02-03 18:12 +0100
Re: Stripping a JSON of extra characters in PHP Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-02-03 23:56 +0000
Re: Stripping a JSON of extra characters in PHP Arno Welzel <usenet@arnowelzel.de> - 2023-02-05 00:28 +0100
Re: Stripping a JSON of extra characters in PHP Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-02-05 00:06 +0000
Re: Stripping a JSON of extra characters in PHP Arno Welzel <usenet@arnowelzel.de> - 2023-02-05 14:17 +0100
Re: Stripping a JSON of extra characters in PHP Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-02-05 20:58 +0000
Re: Stripping a JSON of extra characters in PHP Arno Welzel <usenet@arnowelzel.de> - 2023-02-05 23:38 +0100
Re: Stripping a JSON of extra characters in PHP "J.O. Aho" <user@example.net> - 2023-02-04 11:23 +0100
Re: Stripping a JSON of extra characters in PHP Arno Welzel <usenet@arnowelzel.de> - 2023-02-05 00:30 +0100
Re: Stripping a JSON of extra characters in PHP Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-02-04 23:44 +0000
Re: Stripping a JSON of extra characters in PHP "J.O. Aho" <user@example.net> - 2023-02-05 16:14 +0100
Re: Stripping a JSON of extra characters in PHP doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-02-06 01:31 +0000
Re: Stripping a JSON of extra characters in PHP "J.O. Aho" <user@example.net> - 2023-02-06 08:14 +0100
Re: Stripping a JSON of extra characters in PHP doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-02-06 15:28 +0000
Re: Stripping a JSON of extra characters in PHP "J.O. Aho" <user@example.net> - 2023-02-06 18:14 +0100
Re: Stripping a JSON of extra characters in PHP doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-02-07 00:56 +0000
Re: Stripping a JSON of extra characters in PHP Arno Welzel <usenet@arnowelzel.de> - 2023-02-06 20:40 +0100
Re: Stripping a JSON of extra characters in PHP doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-02-07 00:57 +0000
Re: Stripping a JSON of extra characters in PHP doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-02-07 01:28 +0000
Re: Stripping a JSON of extra characters in PHP Arno Welzel <usenet@arnowelzel.de> - 2023-02-07 09:16 +0100
Re: Stripping a JSON of extra characters in PHP Arno Welzel <usenet@arnowelzel.de> - 2023-02-07 09:31 +0100
Re: Stripping a JSON of extra characters in PHP doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-02-07 16:10 +0000
Re: Stripping a JSON of extra characters in PHP Arno Welzel <usenet@arnowelzel.de> - 2023-02-09 20:22 +0100
Re: Stripping a JSON of extra characters in PHP doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-02-09 21:01 +0000
Re: Stripping a JSON of extra characters in PHP "J.O. Aho" <user@example.net> - 2023-02-10 11:49 +0100
Re: Stripping a JSON of extra characters in PHP doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-02-10 14:39 +0000
Re: Stripping a JSON of extra characters in PHP doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-02-07 16:05 +0000
Re: Stripping a JSON of extra characters in PHP Arno Welzel <usenet@arnowelzel.de> - 2023-02-07 09:13 +0100
Re: Stripping a JSON of extra characters in PHP doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-02-07 16:05 +0000
csiph-web