Barand Posted August 16, 2023 Share Posted August 16, 2023 For decades I have lain awake at night pondering this major conundrum. Why do PDO::FETCH_BOTH and mysqli->fetch_array() exist? Surely one either wants an associative array or, occasionally, a numerically indexed array? Further, given their uselessness, why the hell are they the default? Can anyone enlighten me as to their raison d'être? Quote Link to comment https://forums.phpfreaks.com/topic/317197-one-of-lifes-big-questions/ Share on other sites More sharing options...
requinix Posted August 16, 2023 Share Posted August 16, 2023 Presumably both of them do so to match the original mysql, whose fetch_array returned the combined form. And I'm going to guess it did out of some sense of "maximum usefulness, minimum effort": call the thing that returns an array and you can use it however you want. $_REQUEST will have come out of that same sort of mentality too, back when PHP was treated more like a templating system than a programming language. Quote Link to comment https://forums.phpfreaks.com/topic/317197-one-of-lifes-big-questions/#findComment-1611223 Share on other sites More sharing options...
kicken Posted August 17, 2023 Share Posted August 17, 2023 I always figured it was just a convenience thing so you could either access the data by key or via list() without having to mess with the fetch mode. Quote Link to comment https://forums.phpfreaks.com/topic/317197-one-of-lifes-big-questions/#findComment-1611224 Share on other sites More sharing options...
Barand Posted August 17, 2023 Author Share Posted August 17, 2023 Just don't use foreach() to iterate! Quote Link to comment https://forums.phpfreaks.com/topic/317197-one-of-lifes-big-questions/#findComment-1611225 Share on other sites More sharing options...
gizmola Posted August 19, 2023 Share Posted August 19, 2023 It's a great question. I have to think that it was extra work to create the associative array version, so it never really made a lot of sense why having two versions of the same data returned in the same array, would be the default. Quote Link to comment https://forums.phpfreaks.com/topic/317197-one-of-lifes-big-questions/#findComment-1611285 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.