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
Share on other sites

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

 

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.