User login

Curses: array_merge_recursive doesn't behave as hoped, it creates arrays for matching strings

The PHP function http://us3.php.net/array_merge_recursive doesn't do what I'd hoped. Instead of merely combining nested arrays if it finds them, it creates arrays for values with matching strings.

In the output below uid and biblio_type should be a single, the last-added, value, not an array of a couple values.

<?php
stdClass::__set_state(array(
   'type' => 'biblio',
   'uid' =>
  array (
    0 => 1,
    1 => '160',
  ),
   'status' => true,
   'promote' => false,
   'moderate' => false,
   'sticky' => false,
   'format' => 0,
   'comment' => 0,
   'taxonomy' =>
  array (
  ),
   'biblio_type' =>
  array (
    0 => 129,
    1 => 102,
  ),
   'title' =>
  SimpleXMLElement::__set_state(array(
  )),
   'biblio_citekey' => NULL,
   'biblio_contributors' =>
  array (
    1 =>
    array (
    ),
  ),
   'biblio_date' => '1973 Mar 29',
   'biblio_year' => '1973',
   'biblio_secondary_title' =>
  SimpleXMLElement::__set_state(array(
  )),
   'biblio_alternate_title' =>
  SimpleXMLElement::__set_state(array(
  )),
   'biblio_volume' =>
  SimpleXMLElement::__set_state(array(
  )),
   'biblio_issue' =>
  SimpleXMLElement::__set_state(array(
  )),
   'biblio_issn' =>
  SimpleXMLElement::__set_state(array(
  )),
   'biblio_pages' =>
  SimpleXMLElement::__set_state(array(
  )),
   'biblio_abst_e' => NULL,
   'biblio_url' => '',
   'biblio_custom1' => 'http://www.ncbi.nlm.nih.gov/pubmed/?dopt=Abstract',
))
?>

http://us3.php.net/array_merge does what is desired for these. But that won't merge the taxonomy array recursively, I don't think.

While complaining about little annoyances, what the heck is with the Simple XML Element object deal rather than showing up in var_export as the string it ultimately really is?

Resolution

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.