hi, i want to change an array's key to its values.
the array is like this:
<php
Array ( [0] => category_name: [1] => c1 [2] => types: [3] => t1 )
?>
i want to make the same array's values as key, like below using some array functions or some other functions please help
<?php
Array ( [category_name:] =>c1[types:]=>t1 )
?>
mayuri_desh
0
Newbie Poster
Recommended Answers
Jump to Postfunction toAssoc($arr){ $data=array(); if(is_array($arr)) { for($i=0,$limit=count($arr); $i < $limit; ++$i) { $data[$i]=isset($data[1+$i]) ? $data[1+$i]: ''; ++$i; } } return $data; }
Jump to PostHi,
Try this:
$arrInput = array('abc', 'def', 'ghi', 'jkl', 'mno', 'pqr'); $arrOutput = index_array($arrInput); function index_array($arrInput) { $arrOutput = array(); $intIndex = 0; if(is_array($arrInput)) { while($intIndex <= count($arrInput)) { if(isset($arrInput[$intIndex]) && isset($arrInput[$intIndex + 1])) { $arrOutput[$arrInput[$intIndex]] = $arrInput[$intIndex + 1]; } $intIndex += 2; } } …
All 8 Replies
hielo
65
Veteran Poster
blocblue
238
Posting Pro in Training
Featured Poster
blocblue
238
Posting Pro in Training
Featured Poster
hielo
65
Veteran Poster
mschroeder
251
Bestower of Knowledge
Team Colleague
hielo
65
Veteran Poster
mschroeder
251
Bestower of Knowledge
Team Colleague
hielo
65
Veteran Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.