Jump to content

Array problem PLS HELP


Paldo

Recommended Posts

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

 

<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;

 

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;

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>

 

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

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.