downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

ArrayObject::getArrayCopy> <ArrayObject::count
[edit] Last updated: Fri, 25 May 2012

view this page in

ArrayObject::exchangeArray

(PHP 5 >= 5.1.0)

ArrayObject::exchangeArray配列を別の配列と交換する

説明

public array ArrayObject::exchangeArray ( mixed $input )

現在の配列を、別の配列あるいはオブジェクトと交換します。

パラメータ

input

現在の配列と交換する配列あるいはオブジェクト。

返り値

元の配列を返します。

例1 ArrayObject::exchangeArray() の例

<?php
// フルーツの配列
$fruits = array("lemons" => 1"oranges" => 4"bananas" => 5"apples" => 10);
// ヨーロッパの都市の配列
$locations = array('Amsterdam''Paris''London');

$fruitsArrayObject = new ArrayObject($fruits);

// フルーツを都市と交換します
$old $fruitsArrayObject->exchangeArray($locations);
print_r($old);
print_r($fruitsArrayObject);

?>

上の例の出力は以下となります。

Array
(
    [lemons] => 1
    [oranges] => 4
    [bananas] => 5
    [apples] => 10
)
ArrayObject Object
(
    [0] => Amsterdam
    [1] => Paris
    [2] => London
)



add a note add a note User Contributed Notes ArrayObject::exchangeArray
Dmitri Snytkine 15-Dec-2009 02:11
It seems that input array is always passed by reference.
For example if you have an existing array
$array with some values
then you have an arrayobject $o
and then you do this:
$o->exchangeArray($array);
$o->offsetSet('somekey', 'some value');

Now if you check your $array array, it will have
a key 'somekey' with value of 'some value'

I totally did not expect that, I am sure it was a mistake to pass array by reference by default.

 
show source | credits | stats | sitemap | contact | advertising | mirror sites