This means that there is a syntax error in your PHP - you have not written valid code.
Typically you may have placed either two semi-colons at the end of a line or placed one where there shouldn't be. If you have been using echo or print statements then you may not have closed the print statement correctly. It is quite a descriptive error so you know where it is, but you may need to look at the surrounding lines to see if something there is what is causing the parse error.
0 Comments
The answer is yes, but it depends what you mean by invert. On clarification you wanted to amend the array so that the values and keys switched over, and this is done through using the function array_flip, like this:
<?php $values = array("Fred","Bob","George"); print_r($values); $values = array_flip($values); print_r($values); ?> Which returns: Array ( [0] => Fred [1] => Bob [2] => George ) Array ( [Fred] => 0 [Bob] => 1 [George] => 2 ) If you want to simply see all the values, then you can use print_r or var_dump.
This is done using the range operator which will create an array of the letters:
<?php $letters = range(a,z); ?> This will give you an array from A to Z. If you want to create an array of consecutive numbers in PHP, then you can do it the long hand way...
<?php $myarray = array(1,2,3,4,5,6,7); ?> Or you can do it the easy way, using the range function, which you simply pass the first and last value in the consecutive range. So this is equivalent to the above code: <?php $myarray = range(1,7); ?> ... and when you want an array containing the numbers 1 to a 1,000 - then you'll be glad you learned about this function! If you wish to check whether a value is already stored in an array or not, then use the in_array function.
This is useful when you don't want any duplicates in the array and therefore only want to add a value if it's not already there. The first argument is the string you are testing for and the second is the array you are checking against. Here is an example of in_array in action: <?php $values = array("banana","apple","pear","banana"); $newvalue = "pear"; if (in_array($newvalue,$values)) { echo "$newvalue is already in the array!"; } ?> PHP has 2 special data types that don't fall into the other categories:
Scalar data is data that only contains a single value. As of version 6, PHP features 6 scalar data types
Compound data can contain multiple values. PHP has 2 compound data types:
<?php
$numberofDays = 4; $resDate = mktime(0,0,0,date("m"),date("d")+$numberofDays,date("Y")); echo "Result Date is: ".date("Y/m/d", $resDate); ?> |