I am explaining you, how to reindex an array element in PHP with examples.
we have an array named basicWebsiteInfo[] , we have some website information like website, url. At first, it is indexed correctly as 0,1,2.
<?php
$basicWebsiteInfo = [
'0' => [
'website' => 'webdeveloperindia',
'url' => 'https://webdeveloperindia.in'
],
'1' => [
'website' => 'markdevelopments',
'url' => 'http://markdevelopments.com'
],
'2' => [
'website' => 'pakizacity',
'url' => 'http://pakizacity.com'
],
];
print_r($basicWebsiteInfo);
?>
Result:
Array ( [0] => Array ( [website] => webdeveloperindia [url] => https://webdeveloperindia.in ) [1] => Array ( [website] => markdevelopments [url] => http://markdevelopments.com ) [2] => Array ( [website] => pakizacity [url] => http://pakizacity.com ) )
Now, to understand the reindex array things, at first I am unset it by using the unset() function. The unset() function resets any variable. we want to remove index 1 which is the markdevelopments.
<?php
unset($basicWebsiteInfo[1]);
print_r($basicWebsiteInfo);
?>
Result:
Array ( [0] => Array ( [website] => webdeveloperindia [url] => https://webdeveloperindia.in ) [2] => Array ( [website] => pakizacity [url] => http://pakizacity.com ) )
Hello, Welcome to webdeveloperindia.in. I am a full-stack web developer. Email – [email protected] | Skype – azaruddin23. I have knowledge of PHP, Laravel, Magento 1/2, Codeigniter, WordPress, Joomla, Shopify, Git, Bitbuket, jQuery, Ajax, Javascript and ReactJS.