Answer the question
In order to leave comments, you need to log in
Why does return not return the value of a variable?
In short, I wrote a function that, using parsing, determines how many pages with restaurants are on the site, and the function works properly, I checked every iteration of it and everything works, but as soon as it comes to IF and it is executed, it costs return $ max, but when it does not return the value of the variable, please help, I have been working on this function for the 2nd day
<?php
$page = 0;
function GetMaxPage($page) // C помощью этой фунции я узнаю какая макс. страничка на сайте с ресторанами
{
$subject = file_get_contents('https://restoran.kz/restaurant?page=' . $page);
$pattern = '/<a.+?href="(\/restaurant\?page=[0-9]+){0,1}(.{0,10}){0,1}">([0-9]+)<\/a>/u';
$result = [];
preg_match_all($pattern, $subject, $result);
$max = max($result[3]); // Присваиваю макс значение с массива result
if ($page == $max) {
return $max; // Вот тут и проблема, он не возвращает значение, а если там написать echo то он исправно выводит
} else {
$page = $max;
GetMaxPage($page);
}
}
$MaxPage = GetMaxPage($page);
echo $MaxPage;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question