1

I am trying to create this format of information/Array in PHP

[OverrideEmailSettings] => stdClass Object (
        [[email protected]] => stdClass Object (
            [Reports] => Array (
                    [0] => stdClass Object (
                            [ReportType] => 1
                            [SummaryFrequency] => Array (
                                [0] => stdClass Object (
                                        [FrequencyType] => 8011
                                        [SecondsPast] => 32400
                                )
                            )
                            [Filter] => stdClass Object (
                                [ClauseType] => and
                                [RuleField] => 
                                [RuleOperator] => 
                                [RuleValue] => 
                                [ClauseChildren] => Array (
                                    [0] => stdClass Object (
                                        [ClauseType] => 
                                        [RuleField] => BackupJobDetail.TimeSinceStarted
                                        [RuleOperator] => int_lte
                                        [RuleValue] => 86400
                                    )   
                                )
                            )
                    )
                )
            )
        )

Here is my code - $line = the equivelent to [email protected]

$x = array(
        'Reports' => array(
            'ReportType' => '1',
            'SummaryFrequency' => array(
                'FrequencyType' => '8011',
                'SecondsPast' => '32400',
            ),
            'Filter' => array(
                'ClauseType' => 'or',
                'RuleField' => '',
                'RuleOperator' => '',
                'RuleValue' => '',
                'ClauseChildren' => array(
                    'ClauseType' => '',
                    'RuleField' => 'BackupJobDetail.TimeSinceStarted',
                    'RuleOperator' => 'int_lte',
                    'RuleValue' => '86400',
                ),
            ),
        ),
    );
    
$account_get_user_profile->OverrideEmailSettings->$line = $x;

But I think I have formatted it incorrectly.

5
  • It's not clear what data you are trying to access from that object or how you are trying to access it. Please edit your question to clarify. Commented Dec 20, 2020 at 13:38
  • @JohnConde sorry i put send, i meant create. I'm trying to create that format of array and data in PHP Commented Dec 20, 2020 at 13:39
  • Some of what you are calling an array are Objects!! Commented Dec 20, 2020 at 13:45
  • You need to cast your array ti standard class. Look here: phpize.online/… Commented Dec 20, 2020 at 13:56
  • What is $account_get_user_profile->OverrideEmailSettings->$line = $x; supposed to achieve? Commented Dec 20, 2020 at 14:01

1 Answer 1

2

You need to cast your arrays to stdClass like:

<?php
$x = [
    "Reports" => [
        (object) [
            "ReportType" => "1",
            "SummaryFrequency" => [
                (object) [
                    "FrequencyType" => "8011",
                    "SecondsPast" => "32400",
                ],
            ],
            "Filter" => (object) [
                "ClauseType" => "or",
                "RuleField" => "",
                "RuleOperator" => "",
                "RuleValue" => "",
                "ClauseChildren" => [
                    (object) [
                        "ClauseType" => "",
                        "RuleField" => "BackupJobDetail.TimeSinceStarted",
                        "RuleOperator" => "int_lte",
                        "RuleValue" => "86400",
                    ],
                ],
            ],
        ],
    ],
];

print_r($x);

Look PHP online code

Sign up to request clarification or add additional context in comments.

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.