TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 06-23-2009, 06:04 PM   #1 (permalink)
The Wanderer
 
Join Date: Jun 2009
Posts: 20
Thanks: 2
tech is on a distinguished road
Default 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.
tech is offline  
Reply With Quote
Old 06-23-2009, 06:21 PM   #2 (permalink)
The Addict
 
Join Date: May 2009
Posts: 287
Thanks: 5
adamdecaf is on a distinguished road
Default

Do you have an example of the python code? Also this is a PHP forum, not python.
__________________
My Site
adamdecaf is offline  
Reply With Quote
Old 06-23-2009, 06:31 PM   #3 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

There are multiple times where one can use "index" in Python. Please be more specific and clarify exactly what you need.
Salathe is offline  
Reply With Quote
Old 06-23-2009, 06:32 PM   #4 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

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.
__________________

Village Idiot is offline  
Reply With Quote
Old 06-23-2009, 06:45 PM   #5 (permalink)
The Wanderer
 
Join Date: Jun 2009
Posts: 20
Thanks: 2
tech is on a distinguished road
Default

Quote:
Originally Posted by Salathe View Post
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.
}
}
tech is offline  
Reply With Quote
Old 06-23-2009, 06:51 PM   #6 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

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.
__________________

Village Idiot is offline  
Reply With Quote
Old 06-23-2009, 08:03 PM   #7 (permalink)
The Addict
 
Join Date: May 2009
Posts: 287
Thanks: 5
adamdecaf is on a distinguished road
Default

@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.
__________________
My Site
adamdecaf is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create a gallery class Tanax Advanced PHP Programming 25 02-19-2013 04:25 AM
Can't get PHP 5. to work? Newbie windows PHP guy DotNetTim Absolute Beginners 11 02-01-2013 11:02 AM
Defining your World: All About Constants Wildhoney General 15 01-29-2013 12:32 PM
PHP socket based communication with a python server tripy Advanced PHP Programming 7 07-15-2009 08:20 PM
[Tutorial] How to organize your classes | Part 1 Tanax Advanced PHP Programming 10 03-01-2009 10:08 PM


All times are GMT. The time now is 06:08 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design