06-27-2009, 07:07 PM
|
#1 (permalink)
|
|
The Wanderer
Join Date: Jun 2009
Posts: 20
Thanks: 2
|
help me in my code
hi friend..
I wrote one code in php where i wanted to replacing this element with one of its siblings.but in this line
$index=$this->parent->contents->array_search($replaceWith,$parent->contents);
I have facing problem in array_search,means how to use array_search so my function will work proper.below is my function please correct it as soon as possible.
<?php
function replaceWith($replaceWith)
{
//store old parent
$oldParent=$this->parent;
//get own index in parents contents array
$myIndex=$parent->contents->array_search($this);
if ( $replaceWith->parent==$this->parent)
{
//We're replacing this element with one of its siblings
$index=$this->parent->contents->array_search($replaceWith,$parent->contents);
if ($index && $index < $myIndex)
{
//Furthermore, it comes before this element. That
// means that when we extract it, the index of this
//element will change
$myIndex=$myIndex-1;
}
$oldParent->insert($myIndex,$replaceWith);
}
}
?>
thanks.
|
|
|
|