Paldo Posted May 27, 2009 Share Posted May 27, 2009 Hi guys! Could you please look at this if it could work somehow couse it's not working... Thanks <html> <body> <?php $NumberInStringFormat = $_POST[number]; echo $NumberInStringFormat; echo '<br>'; $lenght = strlen($NumberInStringFormat); echo $lenght; $IdetificatorArray = array( "1" => "ones" , "2" => "tens" , "3" => "hundreats" , "4" => "tousands" , "5" => "tentousands" , "6" => "houndrettousands" , "7" => "milions" , "8" => "tenmilions" , "9" => "houndretmilions" , "10" => "bilions" ); for ($i = $lenght ; $i = 0; $i-- ) { $valueArray = array( '$IdetificatorArray[$i]' => '(int)$NumberInStringFormat($i)' ); } print_r($valueArray); //1 364 720 434 ?> </body> </html> PS: What I was trying to do is get a array, for example if imput $numberInStringFormat is 345 the array should look like this: [hundreats] => 3; // all of these in int format... [tens] => 4; [ones] => 5; Link to comment https://forums.phpfreaks.com/topic/159875-array-problem-pls-help/ Share on other sites More sharing options...
Ken2k7 Posted May 27, 2009 Share Posted May 27, 2009 for ($i = $lenght ; $i = 0; $i-- ) { Your condition is wrong. Change $i = 0 to $i > -1. Link to comment https://forums.phpfreaks.com/topic/159875-array-problem-pls-help/#findComment-843173 Share on other sites More sharing options...
ToonMariner Posted May 27, 2009 Share Posted May 27, 2009 $valueArray = array( '$IdetificatorArray[$i]' => '(int)$NumberInStringFormat($i)' ); should be $valueArray = array( $IdetificatorArray[$i] => $NumberInStringFormat{$i} ); Link to comment https://forums.phpfreaks.com/topic/159875-array-problem-pls-help/#findComment-843178 Share on other sites More sharing options...
Paldo Posted May 27, 2009 Author Share Posted May 27, 2009 ok I change it to a form you can see above but now it say : Parse error: parse error, expecting `')'' in /3w/euweb.cz/p/parobek/zuzkeconfirm.php on line 29 what is actualy the line with the condition... Link to comment https://forums.phpfreaks.com/topic/159875-array-problem-pls-help/#findComment-843194 Share on other sites More sharing options...
gevans Posted May 27, 2009 Share Posted May 27, 2009 show your new code Link to comment https://forums.phpfreaks.com/topic/159875-array-problem-pls-help/#findComment-843198 Share on other sites More sharing options...
Paldo Posted May 27, 2009 Author Share Posted May 27, 2009 <html> <body> <?php $NumberInStringFormat = $_POST[number]; echo $NumberInStringFormat; echo '<br>'; $lenght = strlen($NumberInStringFormat); echo $lenght; $IdetificatorArray = array( "1" => "ones" , "2" => "tens" , "3" => "hundreats" , "4" => "tousands" , "5" => "tentousands" , "6" => "houndrettousands" , "7" => "milions" , "8" => "tenmilions" , "9" => "houndretmilions" , "10" => "bilions" ); for ($i = $lenght ; $i > -1 $i-- ) { $valueArray = array( $IdetificatorArray[$i] => (int)$NumberInStringFormat[$i] ); } print_r($valueArray); //1 364 720 434 ?> </body> </html> PS: What I was trying to do is get a array, for example if imput $numberInStringFormat is 345 the array should look like this: [hundreats] => 3; // all of these in int format... [tens] => 4; [ones] => 5; Link to comment https://forums.phpfreaks.com/topic/159875-array-problem-pls-help/#findComment-843201 Share on other sites More sharing options...
gevans Posted May 27, 2009 Share Posted May 27, 2009 A little bit of looking would've made this a very easy fix for ($i = $lenght ; $i > -1 $i-- ) { should be for ($i = $lenght ; $i > -1; $i-- ) { Link to comment https://forums.phpfreaks.com/topic/159875-array-problem-pls-help/#findComment-843205 Share on other sites More sharing options...
Paldo Posted May 27, 2009 Author Share Posted May 27, 2009 well sorry for that, but that's not the problem couse the ; is missing only here I have it on my page... I'll fix it right away but the problem stays the same.... Parse error: parse error, expecting `')'' in /3w/euweb.cz/p/parobek/zuzkeconfirm.php on line 29 Here is corected code: <html> <body> <?php $NumberInStringFormat = $_POST[number]; echo $NumberInStringFormat; echo '<br>'; $lenght = strlen($NumberInStringFormat); echo $lenght; $IdetificatorArray = array( "1" => "ones" , "2" => "tens" , "3" => "hundreats" , "4" => "tousands" , "5" => "tentousands" , "6" => "houndrettousands" , "7" => "milions" , "8" => "tenmilions" , "9" => "houndretmilions" , "10" => "bilions" ); for ($i = $lenght ; $i > -1 ; $i-- ) { $valueArray = array( $IdetificatorArray[$i] => (int)$NumberInStringFormat[$i] ); } print_r($valueArray); //1 364 720 434 ?> </body> </html> PS: What I was trying to do is get a array, for example if imput $numberInStringFormat is 345 the array should look like this: [hundreats] => 3; // all of these in int format... [tens] => 4; [ones] => 5; Link to comment https://forums.phpfreaks.com/topic/159875-array-problem-pls-help/#findComment-843216 Share on other sites More sharing options...
Ken2k7 Posted May 27, 2009 Share Posted May 27, 2009 Okay, I think it's about time you learn to utilize the tag. For your output, change $valueArray = array( $IdetificatorArray[$i] => (int)$NumberInStringFormat[$i] ); to $valueArray[$IdetificatorArray[$i]] = (int)$NumberInStringFormat[$i]; Link to comment https://forums.phpfreaks.com/topic/159875-array-problem-pls-help/#findComment-843253 Share on other sites More sharing options...
Paldo Posted May 27, 2009 Author Share Posted May 27, 2009 Ok I did what you told me to and now it says: Parse error: parse error in /3w/euweb.cz/p/parobek/zuzkeconfirm.php on line 29 Link to comment https://forums.phpfreaks.com/topic/159875-array-problem-pls-help/#findComment-843286 Share on other sites More sharing options...
Ken2k7 Posted May 27, 2009 Share Posted May 27, 2009 Could you post an updated version of your code using tags? And also specify where line 29 is. Thanks! Link to comment https://forums.phpfreaks.com/topic/159875-array-problem-pls-help/#findComment-843315 Share on other sites More sharing options...
Paldo Posted May 27, 2009 Author Share Posted May 27, 2009 Sorry for beeing such a douche. I realy appreciate your help, I'm kind of new in this stuff... <html> <body> <?php $NumberInStringFormat = $_POST[number]; echo $NumberInStringFormat; echo '<br>'; $lenght = strlen($NumberInStringFormat); echo $lenght; echo '<br>'; echo '<br>'; $IdetificatorArray = array( "1" => "ones" , "2" => "tens" , "3" => "houndrets" , "4" => "tousands" , "5" => "tentousands" , "6" => "houndredtousands" , "7" => "milions" , "8" => "tenmilions" , "9" => "houndredmilions" , "10" => "bilions" ); for ($i = $lenght ; $i > -1; $i-- ) { // this is the line that parse error refers to $valueArray[$IdetificatorArray[$i]] = (int)NumberInStringFormat[$i] ; } print_r($valueArray); ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/159875-array-problem-pls-help/#findComment-843355 Share on other sites More sharing options...
ToonMariner Posted May 28, 2009 Share Posted May 28, 2009 can't see any missing parenthesis but this line for ($i = $lenght ; $i > -1; $i-- ) { // this is the line that parse error refers to should be for ($i = $lenght-1 ; $i = 0 ; $i-- ) { // this is the line that parse error refers to initialize the array before using - that may help... $valueArray=array(); for ($i = $lenght-1 ; $i = 0 ; $i-- ) { // this is the line that parse error refers to Link to comment https://forums.phpfreaks.com/topic/159875-array-problem-pls-help/#findComment-844082 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.