/    Sign up×
Community /Pin to ProfileBookmark

Wh’s The Use Of An Imaginary Array Value ?

Folks,

This is not my code. It’s a code to show pagination section numbers.

[code]
$total_pages = ceil($row_count/$max);
$selfpage = basename(__FILE__);

$query_params = array(
‘find’ => $find,
‘table’ => $table,
‘column’ => $column,
‘max’ => $max
);

for ($i = 1; $i <= $total_pages; $i++) {
$query_params[‘page’] = $i;
$url = $selfpage . “?” . http_build_query($query_params);

echo ‘<a href=”‘ . $url . ‘”>’;

if ($page == $i) { // shouldn’t this be $page_no?
echo ‘<b>’ . $i . ‘</b>’;
} else {
echo $i;
}

echo ‘</a>’;
}
echo ‘<b>’; echo __LINE__; echo ‘</b>’; echo ‘<br>’;
?>
[/code]

It shows Google Type page Numbers: 123456789

Now, I don’t understand one bit of code:
**$query_params[‘page’] = $i;**
Now where did that come from as the $query_params array has no key or value called ‘page’. If I comment-out that bit of code then the code still works. If it works without it then what’s the use of it ? Strange! Let’s call this imaginarry array value. Shall we ?

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJul 26.2021 — > @developer_web#1634720 the $query_params array has no key or value called 'page'.

Then in that case it creates a new array element with that key and value. Whether or not you actually _need_ it later is a separate issue.
×

Success!

Help @developer_web spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...