Jump to content

asker54

New Members
  • Posts

    5
  • Joined

  • Last visited

asker54's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Ch0cu3rThanks. Can you please tell me where can I read about that <?= is equivalent to the syntax <?php echo
  2. @kicken @Ch0cu3r I also thought like yours, but when I substitute <?= with <?php echo , I get the error Values Notice: Undefined index: submitted in C:\wamp\www\general\sortingarray.php on line 46 unsorted: and when I leave it as it is, I get no error. Here is the code I am applying: <?php function userSort($a, $b) { // smarts is all-important, so sort it first if ($b == "smarts") { return 1; } else if ($a == "smarts") { return −1; } return ($a == $b) ? 0 : (($a < $b) ? −1 : 1); } $values = array( 'name' => "Buzz Lightyear", 'email_address' => "buzz@starcommand.gal", 'age' => 32, 'smarts' => "some" ); if ($_POST['submitted']) { $sortType = $_POST['sort_type']; if ($sortType == "usort" || $sortType == "uksort" || $sortType == "uasort") { $sortType($values, "user_sort"); } else { $sortType($values); } } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?> " method="post"> <p> <input type="radio" name="sort_type" value="sort" checked="checked" /> Standard<br /> <input type="radio" name="sort_type" value="rsort" /> Reverse<br /> <input type="radio" name="sort_type" value="usort" /> User-defined<br /> <input type="radio" name="sort_type" value="ksort" /> Key<br /> <input type="radio" name="sort_type" value="krsort" /> Reverse key<br /> <input type="radio" name="sort_type" value="uksort" /> User-defined key<br /> <input type="radio" name="sort_type" value="asort" /> Value<br /> <input type="radio" name="sort_type" value="arsort" /> Reverse value<br /> <input type="radio" name="sort_type" value="uasort" /> User-defined value<br /> </p> <p align="center"><input type="submit" value="Sort" name="submitted" /></p> <p>Values <?php echo $_POST['submitted'] ? "sorted by {$sortType}" : "unsorted"; ?>:</p> <ul> <?php foreach ($values as $key => $value) { echo "<li><b>{$key}</b>: {$value}</li>"; } ?> </ul> </form> Thanks
  3. I met with the ternary operator statement <p>Values <?= $_POST['submitted'] ? "sorted by {$sortType}" : "unsorted"; ?>:</p> I do understand what the statement mean except the the equality sign after the question mark. I would appreciate it if any one would explain what did it mean. Thanks
×
×
  • 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.