How can I change the named keys in an associative array

ben_eire

The following code returns an associative array as follows

Array ( [1] => Array ( 
   [url] => example.com
   [title] => Title.example
   [snippet] => snippet.example 
) )

$blekkoArray = array();                     

    foreach ($js->RESULT as $item)
    {   
        $blekkoArray[$i]['url'] = str_replace ($find, '', ($item->{'Url'}) );         
        $blekkoArray[$i]['title'] = ($item->{'url_title'});
        $blekkoArray[$i]['snippet'] = ($item->{'snippet'});
        $i++;
    }

    print_r ($blekkoArray);

How can I modify the array so that instead of the array element been identified by 1,2,3 etc it would be identified by the url eg.

Array ( [example.com] => Array ( 
   [title] => Title.example
   [snippet] => snippet.example 
) )
exussum

The other solutions seem to focus on changing the array after

foreach ($js->RESULT as $item)
    {   
        $blekkoArray[str_replace ($find, '', ($item->{'Url'}))] = array(         
        'title'=> $item->{'url_title'},
        'snip pet' => $item->{'snippet'}
         );

    }

That should make the array how you need it

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How to remove the keys from a multi-dimensional associative array?

From Dev

Filter associative array with keys array

From Dev

How to get keys of an associative array as an array

From Dev

how to use strings as associative array keys?

From Dev

How to declare and initialize an associative array with string as keys and arrays as value

From Dev

Merge associative array using a mapping array with an array with partial keys ( support for named parameters )

From Dev

How can I copy associative array items to another single array item recursively?

From Dev

Split associative array based on keys

From Dev

How can I build an associative array recursively using keys from another array?

From Dev

Convert array of keys to associative array

From Dev

How can I get the prev/next key from an associative array?

From Dev

Php, how to swap two associative array KEYs?

From Dev

How can I change the keys to change desktop in windows 10 with autohotkey?

From Dev

How to convert a PHP array to an associative array, using index as keys?

From Dev

How can I print an associative array as a matrix

From Dev

How can I create an associative array from a foreach loop?

From Dev

PHP: How to extract() values from an associative array with hyphens/dashes in their keys?

From Dev

Is the behaviour of associative array keys in php 8.0.2 different to php 7? Should I enclose array keys in quotes, or not?

From Dev

Modify array keys of an associative array

From Dev

How do I define an associative array?

From Dev

How can I push keys to an unsorted array?

From Dev

Merge associative array using a mapping array with an array with partial keys ( support for named parameters )

From Dev

How to get the i'th element of an associative array?

From Dev

How to iterate through an associative array properly, when one of the keys is "1"?

From Dev

PHP: How to extract() values from an associative array with hyphens/dashes in their keys?

From Dev

How can I change the keys of an unsorted array to what they would be if the array was sorted?

From Dev

How to assign new keys to a PHP associative array

From Dev

How can I statically declare a Javascript object instance (a.k.a "associative array") whose property names (a.k.a keys) contain dashes?

From Dev

How can I make dynamic associative array with jquery?

Related Related

  1. 1

    How to remove the keys from a multi-dimensional associative array?

  2. 2

    Filter associative array with keys array

  3. 3

    How to get keys of an associative array as an array

  4. 4

    how to use strings as associative array keys?

  5. 5

    How to declare and initialize an associative array with string as keys and arrays as value

  6. 6

    Merge associative array using a mapping array with an array with partial keys ( support for named parameters )

  7. 7

    How can I copy associative array items to another single array item recursively?

  8. 8

    Split associative array based on keys

  9. 9

    How can I build an associative array recursively using keys from another array?

  10. 10

    Convert array of keys to associative array

  11. 11

    How can I get the prev/next key from an associative array?

  12. 12

    Php, how to swap two associative array KEYs?

  13. 13

    How can I change the keys to change desktop in windows 10 with autohotkey?

  14. 14

    How to convert a PHP array to an associative array, using index as keys?

  15. 15

    How can I print an associative array as a matrix

  16. 16

    How can I create an associative array from a foreach loop?

  17. 17

    PHP: How to extract() values from an associative array with hyphens/dashes in their keys?

  18. 18

    Is the behaviour of associative array keys in php 8.0.2 different to php 7? Should I enclose array keys in quotes, or not?

  19. 19

    Modify array keys of an associative array

  20. 20

    How do I define an associative array?

  21. 21

    How can I push keys to an unsorted array?

  22. 22

    Merge associative array using a mapping array with an array with partial keys ( support for named parameters )

  23. 23

    How to get the i'th element of an associative array?

  24. 24

    How to iterate through an associative array properly, when one of the keys is "1"?

  25. 25

    PHP: How to extract() values from an associative array with hyphens/dashes in their keys?

  26. 26

    How can I change the keys of an unsorted array to what they would be if the array was sorted?

  27. 27

    How to assign new keys to a PHP associative array

  28. 28

    How can I statically declare a Javascript object instance (a.k.a "associative array") whose property names (a.k.a keys) contain dashes?

  29. 29

    How can I make dynamic associative array with jquery?

HotTag

Archive