It is possible to call a View using PHP code. It is also possible modify a view using code such as hook_views_pre_view()
to change how a View is displayed dynamically.
I actually wouldn't do either for your request. Simply do the following:
- In your View make 2
displays
.
- 1 view display that shows the Grid format.
- 1 view display that shows the list format.
On the page in question use an HTML button, html link, or even a Rules Link that uses Ajax to reload the div on the page and calls the view with the correct display mode you want. Your ajax call will be calling like: $view = views_embed_view('MY_VIEW_NAME', 'display_id');
and updating the page with $view
contents via Ajax.
So make 2 view displays, and learn how to call them using Ajax.