TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   php function which work same as python index (http://www.talkphp.com/absolute-beginners/4596-php-function-work-same-python-index.html)

tech 06-23-2009 06:04 PM

php function which work same as python index
 
dear all ..
any one can u please tell me that a function which work same as index of python and how to use it.
thanks.

adamdecaf 06-23-2009 06:21 PM

Do you have an example of the python code? Also this is a PHP forum, not python.

Salathe 06-23-2009 06:31 PM

There are multiple times where one can use "index" in Python. Please be more specific and clarify exactly what you need.

Village Idiot 06-23-2009 06:32 PM

You will need to provide more information before we can be of use to you here. Are you referring to str.index() in python? If so strpos is probably what you are looking for. Otherwise we need to know more specifically what you want.

tech 06-23-2009 06:45 PM

Quote:

Originally Posted by Salathe (Post 25907)
def replaceWith(self, replaceWith):
#store old parent
oldParent = self.parent
#get own index in parents contents array
myIndex = self.parent.contents.index(self)
# if mine and replaceWith's parent is same
if hasattr(replaceWith, 'parent') and replaceWith.parent == self.parent:
# We're replacing this element with one of its siblings.
index = self.parent.contents.index(replaceWith)
if index and 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
#delete me; kill me
self.extract()
#insert replacewith at myIndex
oldParent.insert(myIndex, replaceWith)

in this code index method i wanted to use a method which work same as index in php.
here is the php code what i have written.
function replaceWith($replaceWith)
{
$oldParent=$this->parent;
$myIndex=$parent->contents->array_search($this);
if ( $replaceWith->parent==$parent))
{
$index=$this->parent->contents->index($parent,$replaceWith)
if ($index && $index < $myIndex)
{
$myIndex=$myIndex-1;
}
$oldParent->insert($myIndex,$replaceWith) //insert function will be developed letter.
}
}

Village Idiot 06-23-2009 06:51 PM

I don't know any python, everything I've been getting was from documentation. So I ask again, what are you trying to do? There are multiple contexts in which index is used, before I can help you I need to know which context you are trying to use it in.

adamdecaf 06-23-2009 08:03 PM

@tech your using index in several different meanings, which one (or many) are you trying to use. Index in python is a recurring keyword with different usage(s) based on its context.


All times are GMT. The time now is 09:17 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0