Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Uporządkowanie kodu php/xml
shpaque
post 8.06.2018, 09:04:43
Post #1





Grupa: Zarejestrowani
Postów: 651
Pomógł: 3
Dołączył: 31.01.2011
Skąd: Warszawa

Ostrzeżenie: (10%)
X----


Witam serdecznie,
jako że jestem "młodym" programistą xml - wczesniej działałem sobie na csv i tablicach, mam pytanie, czy dobrze zapisuję kod, czy powinno się to robić w jakiś inny sposób.

z pliku xml wyciagam sobie dane:

  1. hostingDataBase = simplexml_load_file('./../db/hosting.xml') or die ('Błąd: Brak obsługi funkcji SimpleXML');
  2. $currentHosting = $hostingDataBase -> current -> customer;
  3. $countCurrent = count($currentHosting);
  4. $archiveHosting = $hostingDataBase -> archive -> customer;
  5. $countArchive = count($archiveHosting);
  6. $cHosting = array();
  7. $aHosting = array();
  8.  
  9. foreach ($currentHosting as $cH)
  10. {
  11. $cHosting[] = $cH;
  12. }
  13.  
  14. foreach ($archiveHosting as $aH)
  15. {
  16. $aHosting[] = $aH;
  17. }
  18.  
  19. array_multisort(array_column($cHosting, 'date'), SORT_FLAG_CASE | SORT_STRING, array_column($cHosting, 'name'), SORT_FLAG_CASE | SORT_STRING, $cHosting);
  20. array_multisort(array_column($aHosting, 'date'), SORT_FLAG_CASE | SORT_STRING, array_column($aHosting, 'name'), SORT_FLAG_CASE | SORT_STRING, $aHosting);


wszystkie dane są w korzeniu "customer" tablice buduja sie jak widac array0 -> i tu wszystkie pola z korzenia customer...
jak zrobic tablice na zasadzie takiej:

  1. $hostingDataBase = './../db/hosting.csv';
  2. $hostingColumns = ['hostingName', 'hostingWeb', 'hostingCat', 'hostingDate', 'nazwaLogin', 'nazwaPasword', 'hostingDescription'];
  3. $hostings = array_map(function ($record) use ($hostingColumns) {return array_combine($hostingColumns, str_getcsv($record, '|'));}, file($hostingDataBase));


bo tak byloby mi najlatwiej

zeby tablica byla zbudowana z
  1. array(name => $xml -> customer -> name, id => $xml -> customer -> id) etc


...chcialbym sobie zmienne z tablicy wywolywac na zasadzie:
  1. foreach($currentCustomers as $cC)
  2. {
  3. $cC['name'] = blebleble;
  4. $cC['id'] = blablabla;
  5. ...


@EDIT

ok doszedłem - dzisiaj mózg wyspany, szybko sobie poradziłem. Chodziło mi o to:

  1. foreach ($currentHosting as $key => $cH)
  2. {
  3. $cHosting[] = ['date' => $cH -> date, 'www' => $cH -> www, 'name' => $cH -> name...];
  4. }


Ten post edytował shpaque 8.06.2018, 08:51:04
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 28.03.2024 - 20:58