String into array

52
August 07, 2018, at 5:30 PM

I have a string like:

     {
        "OperationResult": [
                 {
                   "CA::Read:PackageItems": {
                           "Read.PackageItem.RemoteBalanceAssigned": false,
                           "Read.PackageItem.CLSpvInfo": "1|-1#-9223372036854775000",
                           "PackageList": 
                             [ 
                               "TopSim-4GSim1GBData", 
                               "TopSim-ATBReactivation"
                             ],
                           "PackageTypeList": 
                             [
                                "optional-unsubscribed", "optional-unsubscribed"
                             ],
                          "PackageFunctionalNameList": 
                                [
                                  "FreeUnits", 
                                  "AccumulationReward+MultipleThresholds"
                                ],
                          "PackageSubStateList": 
                            [
                              "",
                              ""
                            ],
                          "PackageEligibilityList": 
                          [ 
                            true, 
                            true
                          ]
            }
        }]
    }

I am trying to get it into array. but I want filter this string and only put PackageList":["xxxx-yyy","zzz-zzz"] and "PackageSubStateList":[TRUE,FALSE]}

Any thing in between should be filter out.

The resulted array should be like:

PackageList {
               name: xxxx-yyy,
               state: TRUE,
             }
               ....
Answer 1
//The json posted in the question is invalid, assuming valid json gets used here afterwards:
$string = '{"OperationResult":[{"CA::Read:PackageItems":{"PackageList":["xxxx-yyy","zzz-zzz"],
"PackageTypeList":["optional-unsubscribed","optional-"optional-unsubscribed""],
"PackageFunctionalNameList":["FreeUnits","AccumulationReward+MultipleThresholds"],
"PackageSubStateList":[TRUE,FALSE]}';
$object = json_decode($string);
$wanted = $object['OperationResult']['CA::Read:PackageItems'];

$wanted should now contain what you need

READ ALSO
Fatal error: Uncaught Error: Call to undefined function oci_connect() while running the php script through command prompt

Fatal error: Uncaught Error: Call to undefined function oci_connect() while running the php script through command prompt

I have a php script which uploads data to oracle databaseWhen i am running it through my web browser it is working fine

59
Restricting actions with Policies

Restricting actions with Policies

In my Laravel application, a User can have a Profile which they or a user with privileges can update

46
Make coupon field mandatory for a product category in WooCommerce

Make coupon field mandatory for a product category in WooCommerce

I am trying to make it so the coupon field is mandatory on Woocommerce for a product categoryI have tried to use the code from this answer but it only works with a set of coupon code

52
How to Send Amount info with Paypal Express Checkout in PHP

How to Send Amount info with Paypal Express Checkout in PHP

i am developing a eCommerce website in which i am using paypal express checkoutI've created my own Cart system and want to send requested amount related info with paypal express checkout button

41