Php – How to push hash into array of hash in php

hash, php

Like array_push() where we can push an element in to array. I want to push an hash [name,url] in to an array of hash.

Best Solution

If you're referring to associative arrays where the key is user-provided (rather than an auto-incrementing numeric field), just use direct syntax:

$a = Array();$a['name'] = 'url';

Note that $a = Array(); array_push($a, 'lol'); is (almost) the same as $a = Array(); $a[] = 'lol';. array_push is just a (pointless) "shortcut" for the same syntax, which only works for automatic, numeric indexes.

I strongly recommend reading the PHP manual section on the topic. That's what it's there for.