How to set value as key in PHP array?By Hardik Savani | April 8, 2016 | | 796 Viewer | Category : PHP
Sometimes, we work on big php or other framework projects and we need to change array value as array key at that time you can learn from this post. In this example you can do that without foreach loop. For example if you have all country array but that array have key like 1,2,3,4... etc and value is country. at that time you need to make array like country as key and value both that way you can store it on database table directly.
We can do that using array_combine() of PHP array. array_combine() take two argument and both should be array. so, let's see exmple.
$myArray = ['1'=>'US','2'=>'India','3'=>'Brazil','4'=>'Germany'];
$result = array_combine($myArray,$myArray);
[US] => US
[India] => India
[Brazil] => Brazil
[Germany] => Germany
- Codeigniter 3 - CRUD(Create, Read, Update and Delete) using JQuery Ajax, Bootstrap, Models and MySQL
- How to use soft delete in Laravel 5?
- Simple Example of Bootstrap Lightbox Plugin with demo
- How to create scroll to top of the page by jquery animate ?
- Jquery - input tags plugin example using jquery.tagsinput.js plugin
- Jquery Datepicker example code with demo using Jquery UI
- How to check column exists or not in table Laravel 5
- Angular $scope.form value undefined on submit in ionic framework.