TRENDING NEWS

POPULAR NEWS

Php Question. What Is The Result Of 3 4*6

PHP Send Results - Make Phone Number if (xxx)xxx-xxxx Format?

If all numbers have the same pattern (xxx xxx xxxx), use regular expression to delete everything except numbers:

$result=preg_replace("/[^0-9]/","", $phone_number );

and then use substr to divide string into 3 parts - (xxx), xxx and xxxx:

$n1="(".substr( $result ,0,3).")"; //there will be: (xxx)
$n2=substr( $result ,3,3); //there will be: xxx
$n3="-".substr( $result ,6); //there will be: -xxxx

And then connect those three variables, and it's done! ;)
Hope it's understandable. :)

Php array () question?

Please can some one look at my code. I am supposed to create an array and print the contents of the array. I wrote this php code but it renders this:

current interest rates are offered:

"; echo "$RatesArray[0]
"; echo "$RatesArray[1]
"; echo "$RatesArray[2]
"; echo "$RatesArray[3]
"; echo "$RatesArray[4]
"; echo "$RatesArray[5]
"; echo "$RatesArray[6]
"; ?>


which is not what I am looking for. Please tell me what I am doing wrong. Here is my code:





Interest Array




$InterestRate1 = .0725;
$InterestRate2 = .0750;
$InterestRate3 = .0775;
$InterestRate4 = .0800;
$InterestRate5 = .0825;
$InterestRate6 = .0850;
$InterestRate7 = .0875;

$RatesArray = array($InterestRate1, $InterestRate2, $InterestRate3, $InterestRate4, $InterestRate5, $InterestRate6, $InterestRate7);



echo "

current interest rates are offered:

";
echo "$RatesArray[0] ";
echo "$RatesArray[1] ";
echo "$RatesArray[2] ";
echo "$RatesArray[3] ";
echo "$RatesArray[4] ";
echo "$RatesArray[5] ";
echo "$RatesArray[6] ";
?>






Thanks in advance!

The equal volume of two HCL solutions of pH=3 and pH=5 were mixed. What is the pH of the resulting solution?

The pH of a solution is a measure of the concentration of H+ ions which is again the no. of H+ ions divided by the volume. And HCl dissociates completely.

Why is the range() PHP function not working ?

Firstly, you don't have to declare the $numbers variable twice.

Second, the problem is not with the range() function. Even if you delete that line and just have the $numbers = array() line, the output will be the same.

The range() function created an array, so to output the contents you have to be more specific.

For instance, if you wanted to output the first number in the array, you would type:


$numbers = range(1,10);

echo $numbers[0];

?>

Or you could use it in loop:


$numbers = range(1,10);

foreach ( $numbers as $number ) {
// Do stuff...
}

If you just want to output the contents as a list of numbers, you would do this:

$i = 0;
while ( $i < 10 ) {
echo $numbers[$i];
$i++;
}

Missing array items with PHP function array_diff()?

You are probably iterating the array with a for loop, rather than a foreach.

$taken = array(1, 2, 3, 8, 9, 10, 11);
$avail = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32);
$result = array_diff($avail, $taken);

//notice that $result array is indexed
//with larger array's indexes;
print_r($result);
echo "
";

//$result array has 25 items;
//thus, using for loop restricted by count,
//only cells 1-25 are output;
//cells with address > 25 aren't included
for($i = 0; $i < count($result); $i++) {
echo "$result[$i], ";
}
echo "
";

//foreach returns all cells in array
//without regard for their index
foreach($result as $output) {
echo "$output, ";
}
?>

I want to increment an associative array keys in php?

// treat this string as an array
$str = 'Hello';
// the result array
$arr = array();

// incrementor
$i = 3;
$j = 0;

// loop
for ($i, $j; $j < strlen($str); $i++, $j++)
{
$arr[$i] = $str[$j];
}

// show result
echo '

'; 
print_r($arr);
?>

.hth

Php and flash variables?

There are several ways to do it, and you can find more answers to your question on Macromedia website. In general, here are 2 ways:

1. Pass PHP variable to Flash via the "PARAM" tags which embed the flash file. See macromedia website for how to use them. Here's an example:








2. Use Flash's function loadVars to load up a PHP page that generate variable information in the form of "param1=val1¶m2=val2..." and so on.

TRENDING NEWS