1

I have a long array such as:

$userLogs = array(
    'report-abuse-key' => array(
        'name' => null,
        'path' => null,
        'code' => 'report-abuse-page',
        'header' => 'Would you like to proceed?',
        'link-in-navigation-menu'=>null,
        'navigation-menu-in-page'=>'Show',
        'meta'=>array(
            'show'=>null,
            'title'=>'//GET HEADER VALUE HERE//',
            'description'=>null,
            'keywords'=>null,
            'refresh'=>null,
            'canonical'=>null,
            'noindex-tag'=>'Show',//'null' = Do SEO; 'Show' = No SEO;  
            ),
        ),
);

I would like to get the value from $userLogs['header'] and have it duplicated in $userLogs['meta']['title'] i.e. I want it to have it replicated and update automatically without using copy/paste.

5
  • can't you assign 'title' => $userLogs['header'], directly? Commented May 15, 2017 at 12:52
  • Hi. It doesn't work. Commented May 15, 2017 at 12:55
  • can you write your code part, what have you implemented to achieve this so far? Commented May 15, 2017 at 12:56
  • Hi, its above... Its the array. I want to replicate 'header' => 'Would you like to proceed?', in 'title'=>'//GET HEADER VALUE HERE//', Commented May 15, 2017 at 12:57
  • you have to explain what are you trying to do, your question doesn't sound logical, it may be XY problem. Commented May 15, 2017 at 13:01

1 Answer 1

1

You can use php reference. You need to assign the reference of your header variable to the title variable. After this the title value will have reference to header . Any update in header will update the title as well

<?php
$userLogs = array(
    'report-abuse-key' => array(
        'name' => null,
        'path' => null,
        'code' => 'report-abuse-page',
        'header' => 'Would you like to proceed?',
        'link-in-navigation-menu'=>null,
        'navigation-menu-in-page'=>'Show',
        'meta'=>array(
            'show'=>null,
            'title'=>'//GET HEADER VALUE HERE//',
            'description'=>null,
            'keywords'=>null,
            'refresh'=>null,
            'canonical'=>null,
            'noindex-tag'=>'Show',//'null' = Do SEO; 'Show' = No SEO;  
            ),
        ),
);

$userLogs['report-abuse-key']['meta']['title'] = &$userLogs['report-abuse-key']['header'];

$userLogs['report-abuse-key']['meta']['title'] = 'Updated';
echo '<pre>';
print_r($userLogs);exit;

Result

Array
(
    [report-abuse-key] => Array
        (
            [name] => 
            [path] => 
            [code] => report-abuse-page
            [header] => Updated
            [link-in-navigation-menu] => 
            [navigation-menu-in-page] => Show
            [meta] => Array
                (
                    [show] => 
                    [title] => Updated
                    [description] => 
                    [keywords] => 
                    [refresh] => 
                    [canonical] => 
                    [noindex-tag] => Show
                )

        )

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

2 Comments

Better to add results of print_r.
@ImranZahoor Added the result set as well. Thanks

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.