Separate areacode from phone number string with MySQL Database
Assuming my understanding of the question and the data is correct:


  Did I get it right that you want to map your phone number to the area matching the most initial digits? Having 035, 0352, 03522 and 035225 you would expected the location of 035225 for 03522522492? 


I would try a SQL-only approach:

SELECT * 
FROM Areacodes 
WHERE Areacode IN ('032','0352','03522','035225') 
ORDER BY CHAR_LENGTH(deliveryAddress_zip) DESC 
LIMIT 0,1


So in PHP you now only need to build the IN-clause. Split the phone number in substrings of suitable length (I guess 3-6 digits for Germany).

Without any validation the snipped could look like:

$phone = "03522522492";

$parts = [];
for ($len = 3; $len &lt;= 6; $len++) $parts[] = substr($phone, 0, $len);
$in = "'" . implode("','", $parts) . "'";

echo $in;
//'035','0352','03522','035225'