phpsane Posted February 3, 2019 Share Posted February 3, 2019 Long Version Associative Array: /* associative array */ $row = mysqli_fetch_array($result, MYSQLI_ASSOC); echo $row["name"]." ".$row["author_name"]." ".$row['price']; Short Version Associative Array: ($row = mysqli_fetch_assoc($result)) As in: while ($row = mysqli_fetch_assoc($result)) { echo $row["name"]." ".$row["class"]." ".$row['roll_no']."<br />"; Q1. Correct ? Q2. Long Version Numeric Array: /* numeric array */ $row = mysqli_fetch_array($result, MYSQLI_NUM); echo $row[0]." ".$row[1]." ".$row[2]; Can you not do short Version like this : ($row = mysqli_fetch_num($result)) As in: while ($row = mysqli_fetch_num($result)) { echo $row["name"]." ".$row["class"]." ".$row['roll_no']."<br />"; Q3. Long Version "Both": /* associative and numeric array */ $row = mysqli_fetch_array($result, MYSQLI_BOTH); echo $row[0]." ".$row["author_name"]." ".$row[2]; Can you not do short Version like this: ($row = mysqli_fetch_both($result)) As in: while ($row = mysqli_fetch_both($result)) { echo $row["name"]." ".$row["class"]." ".$row['roll_no']."<br />"; Link to comment Share on other sites More sharing options...
Barand Posted February 3, 2019 Share Posted February 3, 2019 Why don't you RTFM for a change instead of asking us to read it to you? Link to comment Share on other sites More sharing options...
phpsane Posted February 3, 2019 Author Share Posted February 3, 2019 48 minutes ago, Barand said: Why don't you RTFM for a change instead of asking us to read it to you? I did not find these shortcuts I mention in the FM. Did you ? Link to comment Share on other sites More sharing options...
requinix Posted February 3, 2019 Share Posted February 3, 2019 4 hours ago, phpsane said: I did not find these shortcuts I mention in the FM. Did you ? I did. Because I'm not looking for some damned "shortcuts" in the manual. I'm looking for information about the functions you don't understand how to use. Link to comment Share on other sites More sharing options...
ginerjm Posted February 4, 2019 Share Posted February 4, 2019 Agreeing with the others I find you annoying. I will probably get a censure for my comment but after just dealing with one of your other posts under one of your other identities I cannot understand why you exist since it is obviously not for any need to get real tasks done since all you do is ask stuff that YOU SHOULD ALREADY KNOW if you had any gumption. PS - There are no 'shortcuts' in php. Stop using that term. Try and learn that. Link to comment Share on other sites More sharing options...
requinix Posted February 4, 2019 Share Posted February 4, 2019 2 hours ago, ginerjm said: Agreeing with the others I find you annoying. I will probably get a censure for my comment but after just dealing with one of your other posts under one of your other identities I cannot understand why you exist since it is obviously not for any need to get real tasks done since all you do is ask stuff that YOU SHOULD ALREADY KNOW if you had any gumption. PS - There are no 'shortcuts' in php. Stop using that term. Try and learn that. FYI don't expect a reply from him. He won't be making any more of those. Link to comment Share on other sites More sharing options...
Barand Posted February 5, 2019 Share Posted February 5, 2019 17 hours ago, ginerjm said: PS - There are no 'shortcuts' in php. What about $amount = (isset($_GET['amount'])) ? $_GET['amount'] : 0; $balance = $balance - $amount; versus $amount = $_GET['amount'] ?? 0; $balance -= $amount; Link to comment Share on other sites More sharing options...
ginerjm Posted February 5, 2019 Share Posted February 5, 2019 Under this identity or all? Link to comment Share on other sites More sharing options...
Psycho Posted February 6, 2019 Share Posted February 6, 2019 On 2/5/2019 at 1:41 AM, Barand said: What about $amount = (isset($_GET['amount'])) ? $_GET['amount'] : 0; versus $amount = $_GET['amount'] ?? 0; Mind blown! I never knew the ternary operator could be used like that. I typically use it for defining a variable from POST/GET data similar to that. However, I typically trim() the value within the true condition, so it may not be as useful as I would like, but still . . . Link to comment Share on other sites More sharing options...
Barand Posted February 6, 2019 Share Posted February 6, 2019 It isn't a ternary in the second example, it's php7's new coalesce operator. BTW you could $amount = trim( $_GET['amount'] ?? 0 ); Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.