|
|
|
|
![]() ![]() |
Dec 24 2007, 01:39 AM
Post
#1
|
|
|
Newbie [ Level 2 ] Group: Members Posts: 23 Joined: 24-October 07 Member No.: 25,689 |
I don't know does PHP has any functions which can product a serial 0 to 9 as a string-array
CODE range(0,9) do well, but they are numericCODE range('0','9') is the same above, they are still numericMust I write CODE array('0','1','2'...) (it is a too bad code)?
|
|
|
|
Dec 25 2007, 01:45 AM
Post
#2
|
|
|
Super Member Group: [HOSTED] Posts: 805 Joined: 8-April 06 From: Lima - Peru Member No.: 12,579 myCENTs:46.87 |
I don't know does PHP has any functions which can product a serial 0 to 9 as a string-array CODE range(0,9) do well, but they are numericCODE range('0','9') is the same above, they are still numericMust I write CODE array('0','1','2'...) (it is a too bad code)?You can simply use a string variable to store it, for example: CODE <?php $MyString="0123456789"; echo substr($MyString,0, 1); // outputs 0 echo $MyString[0]; // outputs the same thing, 0 echo $MyString{0}; // outputs the same thing, 0 echo $MyString; // outputs 0123456789 ?> Best regards, |
|
|
|
Dec 25 2007, 03:43 AM
Post
#3
|
|
|
Newbie [ Level 2 ] Group: Members Posts: 23 Joined: 24-October 07 Member No.: 25,689 |
thanks, fortunatly I just need 0 to 9 and your solution seem to be effective
|
|
|
|
Dec 25 2007, 04:01 AM
Post
#4
|
|
|
Super Member Group: [HOSTED] Posts: 805 Joined: 8-April 06 From: Lima - Peru Member No.: 12,579 myCENTs:46.87 |
No problem, i'm glad that it helps you.
BTW, many times simple solutions works better than complicated ones. Best regards, |
|
|
|
Dec 26 2007, 10:09 AM
Post
#5
|
|
|
Newbie [ Level 2 ] Group: Members Posts: 23 Joined: 24-October 07 Member No.: 25,689 |
Well, I have another question which is forgotten asking:
While I write a function, I use some temp variables to store the result and I need to loop some steps but I'm lazy to rewrite them. I'm also don't want to group them as a function then call it because I will have to send the temp variables, which is not necessary. I wonder does PHP has somethings can "jump" through the code lines. For example I write a function like below: CODE function a($var) { switch ($var) { case 'a': condition1 -> do action1 if true break; case 'b': condition2 -> do action2 and actionX if true break; case 'c': condition3 -> do action3 and actionX if true break; default: do actionX } } Suppose that the actionX is writen below default, so how I call it after checking the condition2 or condition3. My English is not good and I really feel it is very hard to explain my trouble so maybe it's hard to understand. As a short, it like GoTo statement in VB language. Anyone who knows it please answer me. |
|
|
|
Dec 27 2007, 05:04 AM
Post
#6
|
|
|
Super Member Group: [HOSTED] Posts: 805 Joined: 8-April 06 From: Lima - Peru Member No.: 12,579 myCENTs:46.87 |
PHP don't have a GOTO statement, function or alike, i'm not 100% sure because i don't know if the latest version of PHP now includes something like this.
Take a look under the user contributed notes of the PHP Switch stament there is a similar function, may be it helps you. Best regards, This post has been edited by TavoxPeru: Dec 27 2007, 06:00 AM |
|
|
|
Dec 27 2007, 09:40 AM
Post
#7
|
|
|
Newbie [ Level 2 ] Group: Members Posts: 23 Joined: 24-October 07 Member No.: 25,689 |
...where it is ? I just find a few lines writen on 18-Jun-2007 11:51.
This post has been edited by PerHapsYouSeen: Dec 27 2007, 09:41 AM |
|
|
|
Dec 28 2007, 02:55 AM
Post
#8
|
|
|
Super Member Group: [HOSTED] Posts: 805 Joined: 8-April 06 From: Lima - Peru Member No.: 12,579 myCENTs:46.87 |
|
|
|
|
Dec 28 2007, 09:03 AM
Post
#9
|
|
|
Newbie [ Level 2 ] Group: Members Posts: 23 Joined: 24-October 07 Member No.: 25,689 |
I will try.
Well, group them as a function or put into a loop is much more simple and I'm going to give up goto. |
|
|
|
Dec 29 2007, 02:29 AM
Post
#10
|
|
|
Super Member Group: [HOSTED] Posts: 805 Joined: 8-April 06 From: Lima - Peru Member No.: 12,579 myCENTs:46.87 |
I guess that you read the reply posted at 25-jun-2007 on the User contributed notes right??? Well, in that post are the reasons to give up the use of labels or goto statements, for the ones that don't have the time to read it and want to know what we are talking about here are the two posts:
QUOTE Okke 25-Jun-2007 05:53 As a reply to zzo38: please don't -ever- use that code. Labels are generally considered a bad programming practise. If you mis-use switch statements in order to simulate the workings of labels, that's double bad. Why not use a simple if/then/else statement? It's readable and less prone to bugs. zzo38 18-Jun-2007 11:51 There is no GOTO command in PHP, but you can do something similar like this: <?php function testfunction($x) {$label='';while(1){switch($label){ case '': if($x==0) continue ($label='fail')*0+1; case 'ok': echo "ok\n"; case 'fail': echo "fail\n"; return; }}} ?> Best regards, |
|
|
|
![]() ![]() |
Similar Topics
| Topics | Topics | |
|---|---|---|
|
|
|
|
Lo-Fi Version | Time is now: 5th December 2008 - 07:49 AM |