Slashdot is powered by your submissions, so send in your scoop

 



Forgot your password?
typodupeerror
×
PHP

Journal dthable's Journal: [PHP] Working with Arrays 2

I've been working on this application that requires adding a key value pair to an existing dictionary. The quick solution I found was:

$one = array( 1 => "one", 2 => "two");
$two = array( 3 => "three", 4 => "four");
$new = array_merge( $one, $two);

Is there some way to just append without the merge? While array_merge works in this case, what if I just want to append a single item? Also, is there an OO implementation of an array? I'd like to be able to say $new->sort() instead of using a function.

This discussion has been archived. No new comments can be posted.

[PHP] Working with Arrays

Comments Filter:
  • you just did something like:

    if (! array_key_exists("key",$array)) {
        array_push($new_key_value,$array);
    }
    have i overlooked something?
    • by dthable ( 163749 )
      That's what I've ended up doing, but it just doesn't sit well with me. It' doesn't seem like a natural operation, plus I haven't found a method to insert into the middle of an array.

The one day you'd sell your soul for something, souls are a glut.

Working...