php - Indexing in the CSV file -


i have csv file indexing 1,2,3 if record 1 contain category xyz 2 contain abc , 3 contain tyu goes well.when subcategories added of xyz index 4 added below 1 , indexing goes 1,4,2,3 whereas want 1,2,3,4.i have used following way:

$filepointer = fopen($category_filename_with_path, 'w') or error('ggg');     foreach($all_category_data_new $updated_data)     {       fputcsv($filepointer,$updated_data);     } 

opening file in appending mode not working.sample format of csv :

62,inspirational||inspirational,1,n,,fande 64,dog$house||doghouse,1,n,,fande 65,doghouse||doghouse,1,n,,fande 66,testauthor||testauthor,1,n,,fande 

thanx in advance

put ksort($all_category_data_new); before foreach solve problem, if want sort keys, independent values array_values($all_category_data_new); solve problem more efficiently.

updated : please add ksort following.

$filepointer = fopen($category_filename_with_path, 'w') or error('ggg'); ksort($all_category_data_new); foreach($all_category_data_new $updated_data) {     fputcsv($filepointer,$updated_data); } 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -